Use Yarn with JFrog CLI

Run Yarn commands with Artifactory integration for dependency resolution and build information collection.

This topic covers the following tasks:

When to Use

Use jf yarn if your JavaScript project uses Yarn for dependency management and you want dependencies resolved from Artifactory. For npm or pnpm, configure Artifactory as your registry using the repository Set Me Up instructions and use the native client, or see the JFrog CLI reference for jf npm and jf pnpm-config.

Prerequisites

  • Yarn 2.4.0 or higher must be installed (Yarn 2.x or 3.x). Yarn 1.x (Classic) and Yarn 4.x are not supported.

    To install a compatible version using Corepack (recommended):

    corepack enable
    corepack prepare yarn@stable --activate

    Or using npm:

    npm install -g yarn@berry

    Note: Running npm install -g yarn without a version tag installs Yarn 1.x, which is not compatible with jf yarn. Always install Yarn 2.x or 3.x.

  • Configure a server with jf config add or jf c add.

  • Authentication to Artifactory is required.

  • Run jf yarn-config in the project directory before the first build.


Configuration: jf yarn-config

Generate Yarn configuration for resolving dependencies through Artifactory. Run this once per project before your first build.

To configure Yarn for Artifactory:

Synopsis

jf yarn-config [options]

Aliases: yarnc

Configuration Options

FlagDefaultDescription
--globalfalseApply configuration globally for all projects
--server-id-resolveArtifactory server ID for dependency resolution
--repo-resolveRepository for resolving dependencies

Configuration Examples

View Help

jf yarn-config --help

Non-Interactive Configuration

Configure Yarn with non-interactive flags:

jf yarn-config --server-id-resolve=<server-id> --repo-resolve=<repo-name>

Where:

  • <server-id>: The server ID configured using jf config add
  • <repo-name>: The name of the npm repository in Artifactory

For example:

jf yarn-config --server-id-resolve=my-server --repo-resolve=npm-virtual

Why Run Config First?

You must run jf yarn-config before jf yarn. The config command creates a .jfrog/projects/yarn.yaml file that directs dependency resolution through Artifactory. Without it, jf yarn does not know where to fetch packages.

If you skip this step, you will see the error: no config file was found! Before running the 'jf yarn' command on a project for the first time, the project should be configured with the 'jf yarn-config' command.

👍

Shortcut

: In CI/CD, pass all flags non-interactively so the config step is fully automated and reproducible.

Configuration Notes

  • Resolution only: Yarn config supports dependency resolution but not deployment. To publish packages, use jf npm publish.
  • Run once per project: Re-run when changing the resolution repository.
  • Yarn version: Requires Yarn 2.4.0 or higher. Works with Yarn 2.x and 3.x.

Expected Output

$ jf yarn-config --server-id-resolve=my-server --repo-resolve=npm-virtual
[Info] yarn build config successfully created.

How to Verify

After running, confirm the configuration exists:

cat .jfrog/projects/yarn.yaml

Build: jf yarn

Run Yarn commands with Artifactory integration for dependency resolution and build information collection.

To run Yarn commands with Artifactory integration:

Synopsis

jf yarn [yarn-command] [options]

Aliases: none

Arguments

ArgumentRequiredDescription
yarn-commandNoYarn command and arguments (for example, install, build)

Build Options

FlagDefaultDescription
--build-nameBuild name for build information (requires --build-number)
--build-numberBuild number for build information (requires --build-name)
--projectJFrog Artifactory project key
--moduleOptional module name for build information

Build Examples

Install Dependencies

jf yarn install

Build with Build Information

jf yarn install --build-name=<build-name> --build-number=<build-number>

Where:

  • <build-name>: A name for the build (for example, my-js-app)
  • <build-number>: A number or identifier for the build run (for example, 1)

For example:

jf yarn install --build-name=my-js-app --build-number=1

Build Output Notes

When running jf yarn install, the CLI prints a Trace ID line before delegating to Yarn:

[Info] Running Yarn...
[Info] Trace ID for JFrog Platform logs: <id>

The Trace ID can be provided to JFrog Support to correlate client-side failures with server-side logs.


Important Notes

  • Yarn version: The CLI requires Yarn 2.4.0 or higher. Yarn 2.x and 3.x are supported. Yarn 1.x (Classic) and Yarn 4.x are not supported. Using jf yarn with Yarn 1.x or 4.x will result in an error.
  • Resolution only: Yarn config currently supports dependency resolution from Artifactory. Deployment (publish) is not supported via jf yarn — use jf npm publish or native yarn npm publish instead.
  • Build-info: Use --build-name and --build-number, then publish with jf rt build-publish.

CI/CD Example (GitHub Actions)

# .github/workflows/build.yml
steps:
  - uses: actions/checkout@v4
  - name: Setup JFrog CLI
    uses: jfrog/setup-jfrog-cli@v4
    env:
      JF_URL: ${{ vars.JF_URL }}
      JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
  - name: Configure Yarn
    run: jf yarn-config --server-id-resolve=setup-jfrog-cli-server --repo-resolve=npm-virtual
  - name: Install dependencies
    run: jf yarn install --build-name=my-js-app --build-number=${{ github.run_number }}
  - name: Publish build info
    run: jf rt build-publish my-js-app ${{ github.run_number }}

Troubleshooting

SymptomCauseFix
no config file was foundjf yarn-config was not runRun jf yarn-config in the project directory
Yarn must have version 2.4.0 or higherYarn 1.x is installed (for example, via npm install -g yarn)Install Yarn 2.x or 3.x: corepack enable && corepack prepare yarn@stable --activate
Error with Yarn 4.xYarn 4.x is not supportedDowngrade to Yarn 3.x: corepack prepare yarn@3 --activate
404 on jf yarn installResolution repository does not exist or name is wrongVerify the repo name matches an existing npm virtual repository in Artifactory
401 / 403 errorsInvalid credentials or insufficient permissionsRe-run jf config add with a valid access token
Cannot publish with jf yarnYarn config is resolution-onlyUse jf npm publish or native yarn npm publish instead

Enable debug logging: export JFROG_CLI_LOG_LEVEL=DEBUG


Related Topics