# jf yarn Run Yarn commands with Artifactory integration for dependency resolution and build information collection. This topic covers the following tasks: * [Configure Yarn for Artifactory (`jf yarn-config`)](#configuration-jf-yarn-config) * [Run Yarn commands (`jf yarn`)](#build-jf-yarn) ## When to Use Use `jf yarn` if your JavaScript project uses Yarn for dependency management and you want dependencies resolved from Artifactory. For npm-based projects, use [`jf npm`](jf-npm.md). For pnpm-based projects, use [`jf pnpm`](jf-pnpm.md). ## Prerequisites * Yarn must be installed (1.x or 2+/Berry; **Yarn 4.x is currently not supported**). * 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 | 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 ```bash jf yarn-config --help ``` #### Non-Interactive Configuration Configure Yarn with non-interactive flags: ```bash jf yarn-config --server-id-resolve= --repo-resolve= ``` Where: * \: The server ID configured using `jf config add` * \: The name of the npm repository in Artifactory For example: ```bash 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**: Works with Yarn 1.x (Classic) and Yarn 2+ (Berry). ### Expected Output ``` $ jf yarn-config --server-id-resolve=my-server --repo-resolve=npm-virtual Yarn build configuration saved successfully. ``` ### How to Verify After running, confirm the configuration exists: ```bash 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 | 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 ```bash jf yarn install ``` #### Build with Build Information ```bash jf yarn install --build-name= --build-number= ``` Where: * \: A name for the build (for example, `my-js-app`) * \: A number or identifier for the build run (for example, `1`) For example: ```bash jf yarn install --build-name=my-js-app --build-number=1 ``` *** ## Important Notes * **Yarn version**: The CLI supports Yarn 1.x (Classic) and Yarn 2+ (Berry). **Yarn 4.x is currently not supported.** Using `jf yarn install` with Yarn 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) ```yaml # .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 | | Error with Yarn 4.x | Yarn 4.x is not supported | Downgrade to Yarn 3.x or earlier | | 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](/artifactory/docs/build-tool-commands) — Capabilities matrix and tool reference * [Native Mode](/artifactory/docs/native-mode) — Supported packages with Native Mode