---
title: "Migrating from yarn to vlt"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/migration/from-yarn"
image: "https://docs.vlt.io/og/client/migration/from-yarn"
lang: "en"
---

# Migrating from yarn to vlt

This guide covers migration from both **yarn v1 (classic)** and **yarn v2+ (berry)**. Key differences are called out where they apply.

## Quick Start

```bash title="Terminal"
# Install vlt globally
$ npm install -g vlt

# Optional: keep npm's registry -- vlt installs through its public npm mirror by default

$ vlt config set registries.npm=https://registry.npmjs.org/

# In your existing project, run:

$ vlt install $ vlt build
```

Unlike yarn, **vlt's default registry is vlt's public npm mirror** (`https://registry.vlt.io/upstream/npm/`, read-only, with usage limits), so package metadata and tarballs come from `registry.vlt.io` with no config. The optional snippet above switches back to the public npm registry; if you have a vlt.io account, run [`vlt setup`](https://docs.vlt.io/client/registries.md#getting-started-with-vlt-setup) instead to use your account's npm mirror (no usage limits). See [Registries](https://docs.vlt.io/client/registries.md).

vlt reads your existing `package.json` files and resolves dependencies. The `yarn.lock` file is not migrated — vlt performs a fresh resolution and creates `vlt-lock.json`.

---

## Command Mapping

| yarn                             | vlt                             | Notes                                                                                       |
| -------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------- |
| `yarn` / `yarn install`          | `vlt install`                   | Does **not** run lifecycle scripts                                                          |
| `yarn add <pkg>`                 | `vlt install <pkg>`             |                                                                                             |
| `yarn add -D <pkg>`              | `vlt install -D <pkg>`          |                                                                                             |
| `yarn remove <pkg>`              | `vlt uninstall <pkg>`           |                                                                                             |
| `yarn run <script>`              | `vlt run <script>`              |                                                                                             |
| `yarn <script>`                  | `vlt run <script>`              | See [fallback-command](https://docs.vlt.io/client/configuring.md#--fallback-commandcommand) |
| `yarn dlx <pkg>` / `npx <pkg>`   | `vlx <pkg>`                     | Run remote packages                                                                         |
| `yarn exec <cmd>`                | `vlt exec <cmd>`                |                                                                                             |
| `yarn init`                      | `vlt init`                      |                                                                                             |
| `yarn pack`                      | `vlt pack`                      |                                                                                             |
| `yarn npm publish`               | `vlt publish`                   |                                                                                             |
| `yarn npm login`                 | `vlt login`                     |                                                                                             |
| `yarn npm whoami`                | `vlt whoami`                    |                                                                                             |
| `yarn workspaces list`           | `vlt list`                      |                                                                                             |
| `yarn why <pkg>`                 | `vlt query '#<pkg>'`            | DSS query; see [Selectors](https://docs.vlt.io/client/selectors.md)                         |
| `yarn install --frozen-lockfile` | `vlt install --frozen-lockfile` |                                                                                             |
| `yarn install --immutable`       | `vlt install --expect-lockfile` |                                                                                             |
| `yarn config set <key> <val>`    | `vlt config set <key>=<val>`    |                                                                                             |
| `yarn up <pkg>`                  | `vlt install <pkg>`             | Re-resolves to latest matching                                                              |

### Shorthand Script Execution

Yarn lets you run scripts without `run` (e.g., `yarn build`). vlt supports this via the `fallback-command` config:

```bash title="Terminal"
$ vlt config set fallback-command=run-exec
```

After setting this, `vlt build` will first check for a vlt command named `build`, and if none matches, look for a `package.json` script.

---

## Configuration

### .yarnrc.yml / .yarnrc → vlt.json

yarn v1 uses `.yarnrc` and `.npmrc`. yarn v2+ uses `.yarnrc.yml`. vlt uses `vlt.json`.

**yarn v2+ example:**

```yaml title=".yarnrc.yml"
# .yarnrc.yml (yarn berry)
npmRegistryServer: "https://registry.internal.company.com/"
npmScopes:
mycompany:
  npmRegistryServer: "https://npm.mycompany.com/"
  npmAuthToken: "abc123"
```

**vlt equivalent:**

```json title="vlt.json"
{
  "registry": "https://registry.internal.company.com/",
  "scoped-registries": {
    "@mycompany": "https://npm.mycompany.com/"
  }
}
```

Auth tokens are stored separately in vlt's keychain, not in config files. See [Authentication](https://docs.vlt.io/client/migration/from-yarn#authentication) below.

**yarn v1 example:**

```ini title=".npmrc"
# .npmrc (yarn classic)
registry=https://registry.internal.company.com/
@mycompany:registry=https://npm.mycompany.com/
```

Same `vlt.json` as above.

---

## Registry Configuration

### Scoped Registries

Both yarn and vlt support scope-to-registry mapping:

```json title="vlt.json"
{
  "scoped-registries": {
    "@mycompany": "https://npm.mycompany.com/"
  }
}
```

### Named Registry Aliases

vlt also supports [named registry aliases](https://docs.vlt.io/client/registries.md), which are more explicit than scoped registries. Dependencies reference a named registry directly, removing ambiguity:

```json title="vlt.json"
{
  "registries": {
    "internal": "https://npm.mycompany.com/"
  }
}
```

```json title="package.json"
{
  "dependencies": {
    "@mycompany/utils": "internal:@mycompany/utils@^2.0"
  }
}
```

---

## Authentication

yarn v1 stores tokens in `.npmrc`. yarn v2+ stores them in `.yarnrc.yml`. Both approaches risk accidental commits of secrets.

vlt stores auth tokens in an XDG-compliant keychain file, separate from project configuration.

```bash title="Terminal"
# Log in to default registry
$ vlt login

# Log in to a custom registry

$ vlt login --registry=https://npm.mycompany.com/
```

### CI Environments

```bash title="Terminal"
# yarn v2+
YARN_NPM_AUTH_TOKEN=abc123 yarn install

# vlt

VLT_TOKEN=abc123 vlt install
```

See [Authentication](https://docs.vlt.io/client/auth.md) for full details.

---

## Lockfile

yarn v1 uses `yarn.lock` (custom format). yarn v2+ also uses `yarn.lock` (YAML-based). vlt uses `vlt-lock.json`.

When you first run `vlt install`, vlt creates `vlt-lock.json` from a fresh resolution. Your `yarn.lock` is not read.

**What to do:**

1. Run `vlt install` to generate `vlt-lock.json`
2. Commit `vlt-lock.json`
3. Optionally remove `yarn.lock` once you've fully switched

---

## Install Script Protection

This is a major difference from yarn.

**yarn v1** runs all lifecycle scripts automatically. **yarn v2+** runs scripts for direct dependencies but blocks transitive dependency scripts by default (you can allowlist via `.yarnrc.yml`).

**vlt** goes further: `vlt install` runs **no scripts at all** by default. The build step is completely separate:

```bash title="Terminal"
# Phase 1: Install (no code executes)
$ vlt install

# Phase 2: Build (runs scripts, skipping known malware)

$ vlt build
```

By default, `vlt build` uses the target `:scripts:not(:built):not(:malware)` — it only runs scripts for packages that need building and aren't flagged as malware by [Socket](https://socket.dev/).

You can target scripts precisely:

```bash title="Terminal"
# Only allow specific trusted packages, saved as allow-scripts
$ vlt build "#esbuild, #node-gyp"
```

Installs then run those scripts.

See [`vlt build`](https://docs.vlt.io/client/commands/build.md) for full details.

---

## Workspaces

### yarn v1

yarn v1 defines workspaces in the root `package.json`:

```json title="package.json (yarn v1)"
{
  "private": true,
  "workspaces": [
    "packages/*"
  ]
}
```

### yarn v2+

yarn v2+ is similar but also supports the `workspaces` field in `.yarnrc.yml` for additional filtering.

### vlt

**Your existing yarn workspaces just work.** vlt reads the `workspaces` field of the root `package.json`, in both the array form above and the object form, where the `nohoist` key is parsed and ignored. `vlt install` copies the globs to `vlt.json` as a plain array, dropping `nohoist`:

```json title="package.json (yarn v1, object form)"
{
  "private": true,
  "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/react-native"
    ]
  }
}
```

Exclusion patterns such as `!packages/legacy` are honored and copied too. The `package.json` `workspaces` field is left as-is for yarn. Commit `vlt.json`: `vlt ci` reads workspaces from it only. The `workspaces` field of `.yarnrc.yml` is not read, so any yarn v2+ filtering defined there needs to move.

yarn v1 has no `workspace:` protocol, so local packages are referenced by plain ranges. `vlt install` then rewrites the ones that link a workspace to `workspace:*` in each `package.json`, see [Rewriting workspace references](https://docs.vlt.io/client/workspaces.md#rewriting-workspace-references). After that, yarn v1 can no longer install the project. To keep it working on the same files, set `"migrate-workspaces": false` in the `config` of `vlt.json`, add the `workspaces` field there yourself, and add `":project > :workspace": "workspace:*"` to `modifiers` to always link them, see [Implicit workspace references](https://docs.vlt.io/client/graph-modifiers.md#implicit-workspace-references). yarn v2+ projects that already use `workspace:` specs need nothing more.

Edit `vlt.json` to use vlt's **named workspace groups** for targeted operations. If `vlt.json` has a `workspaces` field it wins outright, and the `package.json` field is ignored rather than merged, so later `package.json` edits need copying too:

```json title="vlt.json"
{
  "workspaces": {
    "apps": "apps/*",
    "libs": [
      "packages/*",
      "shared/*"
    ]
  }
}
```

```bash title="Terminal"
# Run tests only in the libs group
$ vlt run test --workspace-group libs

# Run build across all workspaces

$ vlt run build --recursive
```

### Workspace Commands

| yarn                            | vlt                                               |
| ------------------------------- | ------------------------------------------------- |
| `yarn workspace <name> <cmd>`   | `cd <path> && vlt <cmd>` or `vlt <cmd> -w <path>` |
| `yarn workspaces foreach <cmd>` | `vlt <cmd> --recursive`                           |

See [Workspaces](https://docs.vlt.io/client/workspaces.md) for full details.

---

## Resolutions → Graph Modifiers

yarn uses `resolutions` in `package.json` to force dependency versions. vlt uses [Graph Modifiers](https://docs.vlt.io/client/graph-modifiers.md) in `vlt.json`.

```json title="package.json (yarn)"
{
  "resolutions": {
    "lodash": "^4.17.21",
    "express/qs": "6.10.0"
  }
}
```

```json title="vlt.json"
{
  "modifiers": {
    "#lodash": "^4.17.21",
    ":root > #express > #qs": "=6.10.0"
  }
}
```

Graph Modifiers use DSS selectors, which give you more precise control over which instances of a dependency are affected.

---

## Plug'n'Play (PnP)

If you're using yarn v2+ with Plug'n'Play (no `node_modules`), the switch to vlt means going back to a `node_modules`-based layout. This is generally straightforward — vlt creates a standard `node_modules` directory.

If your project relies on PnP-specific features (like `.pnp.cjs` loaders), you'll need to remove those references from your build tooling and runtime configuration.

---

## Features Not in vlt

Some yarn-specific features don't have direct equivalents:

- **Plug'n'Play / Zero-Installs** — vlt uses `node_modules`
- **Constraints** — Use vlt's [DSS query system](https://docs.vlt.io/client/selectors.md) for dependency policy enforcement
- **Patches** (`yarn patch`) — Not yet available in vlt
- **Protocols** (`portal:`, `patch:`) — vlt supports `file:`, `workspace:`, `git:`, and `registry:` specifiers

---

## Migration Checklist

1. Install vlt: `npm install -g vlt`
2. Create `vlt.json` with your registry configuration
3. Move scoped registry config from `.yarnrc.yml` / `.npmrc` to `vlt.json`
4. Leave your `workspaces` field in `package.json` — `vlt install` copies it to `vlt.json`
5. Move `resolutions` from `package.json` to `modifiers` in `vlt.json`
6. If using PnP, remove `.pnp.cjs`, `.pnp.loader.mjs`, and related `.yarnrc.yml` settings
7. Run `vlt install` then `vlt build`; yarn v1 local packages referenced by plain ranges are rewritten to `workspace:*`, after which yarn v1 can no longer install the project (to keep it working, see [Workspaces](https://docs.vlt.io/client/migration/from-yarn#workspaces) first)
8. Commit `vlt.json`, `vlt-lock.json` and the `package.json` files
9. Update CI scripts: replace `yarn install --immutable` with `vlt install --expect-lockfile && vlt build`
10. Update CI auth: replace `YARN_NPM_AUTH_TOKEN` with `VLT_TOKEN`
11. Update any `yarn dlx` usage to `vlx`
