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 --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 or 3.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.
Configuration: jf yarn-config
jf yarn-configGenerate 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
| Flag | Default | Description |
|---|---|---|
--global | false | Apply configuration globally for all projects |
--server-id-resolve | — | Artifactory server ID for dependency resolution |
--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 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-virtualWhy 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.yamlBuild: jf yarn
jf yarnRun 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
| 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 (requires --build-number) |
--build-number | — | Build number for build information (requires --build-name) |
--project | — | JFrog Artifactory project key |
--module | — | Optional module name for build information |
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=1Build 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 yarnwith 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— usejf npm publishor nativeyarn npm publishinstead. - Build-info: Use
--build-nameand--build-number, then publish withjf 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
| Symptom | Cause | Fix |
|---|---|---|
no config file was found | jf yarn-config was not run | Run jf yarn-config in the project directory |
Yarn must have version 2.4.0 or higher | Yarn 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.x | Yarn 4.x is not supported | Downgrade to Yarn 3.x: corepack prepare yarn@3 --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 config add with a valid access token |
Cannot publish with jf yarn | Yarn config is resolution-only | Use jf npm publish or native yarn npm publish instead |
Enable debug logging: export JFROG_CLI_LOG_LEVEL=DEBUG
Related Topics
- Build Tools Overview — Capabilities matrix and tool reference
- Native Mode — Supported packages with Native Mode
Updated about 1 month ago
