Use Yarn with JFrog CLI
Configure and run jf yarn with JFrog Artifactory for dependency resolution and build information collection.
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
yarncommands without thejfprefix, 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) for jf yarn in configured-registry (wrapped) mode. Yarn 1.x (Classic) is not supported. jf yarn set version blocks upgrading to Yarn 5.x or higher. 4.x is the maximum supported major version. Native Mode (JFROG_RUN_NATIVE=true) requires Yarn 4.0.0 or higher. See Native Mode.
To install a compatible version using Corepack (recommended):
corepack enable
corepack prepare yarn@stable --activateOr using npm:
npm install -g yarn@berryNote: Running
npm install -g yarnwithout a version tag installs Yarn 1.x, which is not compatible withjf yarn. Always install Yarn 2.x, 3.x, or 4.x.
- Configure a server with
jf config addorjf c add. - Authentication to Artifactory is required.
- Run
jf yarn-configin the project directory before the first build unless you use Native Mode with Yarn 4+.
Configuration: jf yarn-config
jf yarn-configNote: See Prerequisites for supported Yarn versions per mode. Yarn 4.x only switches to Native Mode when
JFROG_RUN_NATIVE=trueis set. See Native Mode.
Generate Yarn configuration for resolving dependencies through Artifactory. Run this once per project before your first build (configured-registry mode).
To configure Yarn for Artifactory:
- From your project directory, run
jf yarn-configwith--server-id-resolveand--repo-resolve(see Non-Interactive Configuration). - Confirm
.jfrog/projects/yarn.yamlexists (see How to Verify).
Synopsis
jf yarn-config [command options]
Aliases: yarnc
Configuration Options
| Flag | Default | Description |
|---|---|---|
--global | false | Set to true to make the configuration global (for all projects). Specific projects can override the global configuration. |
--server-id-resolve | — | Artifactory server ID for dependency resolution. The server should be configured using the jf c add command. |
--repo-resolve | — | Repository for resolving dependencies. |
Configuration Examples
View Help
jf yarn-config --helpNon-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 usingjf 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-virtualWhy 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 publishor nativeyarn npm publish(not viajf yarn). - Run once per project: Re-run when changing the resolution repository.
- Yarn version: See Prerequisites for supported versions per mode.
- Not required in native mode: When
JFROG_RUN_NATIVE=trueand 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.yamlNative Mode
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.
| Requirement | Details |
|---|---|
| Environment variable | JFROG_RUN_NATIVE=true |
| Yarn version | 4.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 file | jf yarn-config is not required |
| Server for build-info | Pass --server-id=<server-id> on the jf yarn command, or rely on the default server from jf config |
| Yarn executable | yarn 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 1Note: Ensure
.yarnrc.ymlalready points at your Artifactory npm virtual repository and includes valid authentication before using native mode.
Build: jf yarn
jf yarnRun Yarn commands with Artifactory integration for dependency resolution and build information collection.
To run Yarn commands through Artifactory:
- Run
jf yarn-configin the project directory if you have not already (see Configuration). - From the project directory, run
jf yarnwith your Yarn command (for example,install) and optional build-info flags (see Build Examples).
Synopsis
jf yarn [yarn command] [command options]
Aliases: none
Arguments
| Argument | Required | Description |
|---|---|---|
yarn-command | No | Yarn command and arguments (for example, install, build) |
Build Options
| Flag | Default | Description |
|---|---|---|
--build-name | — | Build name for build information. --build-number is mandatory when this option is provided. |
--build-number | — | Build number for build information. --build-name is mandatory when this option is provided. |
--project | — | JFrog Artifactory project key. |
--module | — | Optional module name for the build information. --build-name and --build-number are mandatory when this option is provided. |
--server-id | default server | Artifactory 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. |
--threads | 3 | Number of parallel threads used when resolving dependency checksums from Artifactory during build-info collection. |
Build Examples
Install Dependencies
jf yarn installBuild 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=1Yarn Workspaces for 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=DEBUGProvide this ID to JFrog Support to correlate client-side failures with server-side logs.
Important Notes
- Yarn version: See Prerequisites for supported versions per mode.
- Resolution only: Yarn config supports dependency resolution from Artifactory. Deployment (publish) is not supported via
jf yarn— usejf npm publishor nativeyarn npm publishinstead. - Build-info: Use
--build-nameand--build-number, then publish withjf rt build-publish. Dependencies are collected only when both flags are provided. - Native mode: See Native Mode for
JFROG_RUN_NATIVE=truebehavior with Yarn 4+.
CI/CD Example: GitHub Actions
Package Alias (Ghost Frog)
To run
yarnwithout thejfprefix, enable Package Alias insetup-jfrog-cliand setJFROG_CLI_GHOST_FROG=true. If you install the tool after the action (for examplesetup-javaorsetup-node), re-pin the alias path toGITHUB_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
| Symptom | Cause | Fix |
|---|---|---|
no config file was found | jf 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 active | Set JFROG_RUN_NATIVE=true (Yarn 4+) and pass --server-id, or run jf yarn-config |
Yarn version 5.x is not supported | Yarn 5+ requested via yarn set version | Use Yarn 4.x or lower: corepack prepare yarn@4 --activate |
404 on jf yarn install | Resolution repository does not exist or name is wrong | Verify the repo name matches an existing npm virtual repository in Artifactory |
401 / 403 errors | Invalid credentials or insufficient permissions | Re-run jf c add with a valid access token |
The command 'jfrog rt yarn npm publish' is not supported | Publish attempted through jf yarn | Use 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 deps | Pass both build flags. For workspaces, ensure member packages declare registry deps. See Yarn Workspaces |
Native mode ... supported from yarn v4 onwards warning | JFROG_RUN_NATIVE=true with Yarn 2.x/3.x | Upgrade 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 mode | yarn not on PATH while JFROG_RUN_NATIVE=true | Install Yarn and ensure yarn is on PATH before running jf yarn |
Enable debug logging: export JFROG_CLI_LOG_LEVEL=DEBUG
Frequently Asked Questions
This section provides answers to frequently asked questions about using Yarn with JFrog CLI.
FAQs
Q: How do I run Yarn installs with jf yarn and collect build-info?
A: Run jf yarn install with --build-name and --build-number set, then publish the result with jf rt build-publish. See Build: jf yarn.
Q: What do I need before using jf yarn with Artifactory?
A: You need Yarn 2.4.0 or higher, a configured JFrog CLI server, and jf yarn-config run once in the project directory (unless you use Native Mode). See Prerequisites.
Q: What is the difference between configured-registry mode and Native Mode?
A: Configured-registry mode injects Artifactory credentials from jf yarn-config. Native Mode uses your existing .yarnrc.yml settings directly and requires Yarn 4.0.0 or higher. See Native Mode.
Q: Can I publish packages with jf yarn?
A: No. Yarn config supports dependency resolution only. Use jf npm publish or native yarn npm publish to publish packages. See Configuration Notes.
Q: Why is build-info empty after jf yarn install in a workspace?
A: Pass both --build-name and --build-number, and confirm workspace member packages declare registry dependencies. See Yarn Workspaces.
Related Topics
Updated 2 days ago
