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.

📘

Package Alias (Ghost Frog)

To run native yarn commands without the jf prefix, see Use JFrog CLI Package Alias.

Prerequisites

Yarn 2.4.0 or higher must be installed (Yarn Berry: 2.x, 3.x, or 4.x). Yarn 1.x (Classic) and Yarn 5.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, 3.x, or 4.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 unless you use Native mode with Yarn 4+ (see below).

Configuration: jf yarn-config

Note: jf yarn-config is only supported in Yarn 2 to 3. Yarn 4 runs on native mode only.

Generate Yarn configuration for resolving dependencies through Artifactory. Run this once per project before your first build (configured-registry mode).

Synopsis

jf yarn-config [command options]

Aliases: yarnc

Configuration Options

FlagDefaultDescription
--globalfalseSet to true to make the configuration global (for all projects). Specific projects can override the global configuration.
--server-id-resolveArtifactory server ID for dependency resolution. The server should be configured using the jf c add command.
--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 c 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 when using configured-registry mode (the default). 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 or native yarn npm publish (not via jf yarn).
  • Run once per project: Re-run when changing the resolution repository.
  • Yarn version: Requires Yarn 2.4.0 or higher. Supports Yarn 2.x, 3.x, and 4.x.
  • Not required in native mode: When JFROG_RUN_NATIVE=true and Yarn 4+ is installed.

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

Native mode (JFROG_RUN_NATIVE=true)

Native mode runs Yarn using your project's existing .yarnrc.yml registry and authentication settings instead of injecting Artifactory credentials from jf yarn-config. Build information collection still runs when you pass --build-name and --build-number.

RequirementDetails
Environment variableJFROG_RUN_NATIVE=true
Yarn version4.0.0 or higher (required). With Yarn 2.x or 3.x, the CLI logs a warning and falls back to configured-registry mode, which still requires jf yarn-config.
Config filejf yarn-config is not required
Server for build-infoPass --server-id=<server-id> on the jf yarn command, or rely on the default server from jf config
Yarn executableyarn must be available on PATH

Example

export JFROG_RUN_NATIVE=true
jf yarn install --server-id=my-server --build-name=my-js-app --build-number=1
jf rt build-publish my-js-app 1

Note: Ensure .yarnrc.yml already points at your Artifactory npm virtual repository and includes valid authentication before using native mode.


Build: jf yarn

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

Synopsis

jf yarn [yarn command] [command options]

Aliases: none

Arguments

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

Build Options

FlagDefaultDescription
--build-nameBuild name for build information. --build-number is mandatory when this option is provided.
--build-numberBuild number for build information. --build-name is mandatory when this option is provided.
--projectJFrog Artifactory project key.
--moduleOptional module name for the build information. --build-name and --build-number are mandatory when this option is provided.
--server-iddefault serverArtifactory server ID for build-info checksum collection. Supported from Yarn 4+ in native mode (JFROG_RUN_NATIVE=true). In configured-registry mode, the server is taken from .jfrog/projects/yarn.yaml.
--threads3Number of parallel threads used when resolving dependency checksums from Artifactory during build-info collection.

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

Yarn Workspaces (monorepos)

For Yarn workspace projects, a single jf yarn install from the workspace root collects registry dependencies from all workspace members into one build-info module (when --build-name and --build-number are set).

Local workspace links (workspace:), link:, file:, portal:, patch:, and Git URL dependencies are not included in build-info because they do not exist in Artifactory.

Build Output Notes

The CLI generates a Trace ID at the start of every invocation and logs it at DEBUG level. If the command fails, the Trace ID is additionally printed at INFO level:

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

To see the Trace ID on a successful run, enable debug logging:

export JFROG_CLI_LOG_LEVEL=DEBUG

Provide this ID to JFrog Support to correlate client-side failures with server-side logs.

Important Notes

  • Yarn version: Requires Yarn 2.4.0 or higher. Supports Yarn 2.x, 3.x, and 4.x. Yarn 1.x (Classic) and Yarn 5.x are not supported. jf yarn set version 5.x is blocked; use Yarn 4.x or lower.
  • Resolution only: Yarn config 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. Dependencies are collected only when both flags are provided.
  • Native mode: See Native mode for JFROG_RUN_NATIVE=true behavior with Yarn 4+.

CI/CD Example (GitHub Actions)

📘

Package Alias (Ghost Frog)

To run yarn without the jf prefix, enable Package Alias in setup-jfrog-cli and set JFROG_CLI_GHOST_FROG=true. If you install the tool after the action (for example setup-java or setup-node), re-pin the alias path to GITHUB_PATH. See Use JFrog CLI Package Alias.

# .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 }}

For Yarn 4+ projects that already configure Artifactory in .yarnrc.yml:

  - name: Install dependencies (native mode)
    env:
      JFROG_RUN_NATIVE: "true"
    run: jf yarn install --server-id=setup-jfrog-cli-server --build-name=my-js-app --build-number=${{ github.run_number }}

Troubleshooting

SymptomCauseFix
no config file was foundjf yarn-config was not run (configured-registry mode)Run jf yarn-config in the project directory, or use JFROG_RUN_NATIVE=true with Yarn 4+ and a valid .yarnrc.yml
no config file was found with --server-id only--server-id alone does not replace jf yarn-config unless native mode is activeSet JFROG_RUN_NATIVE=true (Yarn 4+) and pass --server-id, or run jf yarn-config
Yarn must have version 2.4.0 or higherYarn 1.x is installed (for example, via npm install -g yarn)Install Yarn 2.x–4.x: corepack enable && corepack prepare yarn@stable --activate
Yarn version 5.x is not supportedYarn 5+ requested via yarn set versionUse Yarn 4.x or lower: corepack prepare yarn@4 --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 c add with a valid access token
The command 'jfrog rt yarn npm publish' is not supportedPublish attempted through jf yarnUse jf npm publish or native yarn npm publish — not jf yarn npm publish
Empty or missing dependencies in build-info--build-name / --build-number not set, workspace root with no registry edges, or only non-registry depsPass both build flags; for workspaces, ensure member packages declare registry deps; see Yarn Workspaces
Native mode ... supported from yarn v4 onwards warningJFROG_RUN_NATIVE=true with Yarn 2.x/3.xUpgrade to Yarn 4+ for native mode, or unset JFROG_RUN_NATIVE and use jf yarn-config
Misleading open : no such file or directory with native modeyarn not on PATH while JFROG_RUN_NATIVE=trueInstall Yarn and ensure yarn is on PATH before running jf yarn

Enable debug logging: export JFROG_CLI_LOG_LEVEL=DEBUG


Related Topics