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

# Migrating from npm to vlt

## 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
```

That's it for basic usage. vlt reads your existing `package.json` and resolves dependencies. Below are the details on what's different and how to handle specific scenarios.

### First: your default registry

Unlike npm, **vlt's default registry is vlt's public npm mirror**, `https://registry.vlt.io/upstream/npm/`, not `registry.npmjs.org`. With no config, package metadata and tarballs for bare specs (like `vlt install express`) come from `registry.vlt.io`. The mirror is read-only and has usage limits; see [Public npm Mirror](https://docs.vlt.io/registry/public-mirror.md).

If you have a vlt.io account, run [`vlt setup`](https://docs.vlt.io/client/registries.md#getting-started-with-vlt-setup) to use your account's npm mirror instead (no usage limits, private packages).

To instead keep npm's behavior, point the `npm` alias at the public npm registry:

```bash title="Terminal"
$ vlt config set registries.npm=https://registry.npmjs.org/
```

Commands that install packages (`vlt install`, `vlt update`, `vlt uninstall`, `vlt ci`, `vlx`/`vlt exec`) resolve bare specs through that alias (or the one named by `default-registry-alias`, if you changed it); a scalar `--registry` / `VLT_REGISTRY` takes precedence for bare specs. The scalar covers bare specs only: `npm:` alias specs, which are common in dependency trees (for example `"string-width-cjs": "npm:string-width@^4.2.0"`), resolve through `registries.npm`. To keep every install off the public mirror, set `registries.npm`, not only `registry`. Publishing and account commands (`vlt publish`, `vlt login`, `vlt whoami`, ...) never use the read-only mirror: configure their registry with `vlt setup`, `--registry` or `publishConfig.registry`.

Or set it in `vlt.json`, pass `--registries npm=<url>` per command, or export `VLT_REGISTRIES`. See [Registries](https://docs.vlt.io/client/registries.md).

---

## Command Mapping

| npm                            | vlt                                                              | Notes                                                                 |
| ------------------------------ | ---------------------------------------------------------------- | --------------------------------------------------------------------- |
| `npm install`                  | `vlt install`                                                    | Does **not** run lifecycle scripts                                    |
| `npm install <pkg>`            | `vlt install <pkg>`                                              | Same behavior                                                         |
| `npm install -D <pkg>`         | `vlt install -D <pkg>`                                           | Same flags                                                            |
| `npm uninstall <pkg>`          | `vlt uninstall <pkg>`                                            | Aliases: `rm`, `u`                                                    |
| `npm install -g <pkg>`         | `vlt install -g <pkg>`                                           | Per-pkg workspace, bins next to `vlt`                                 |
| `npm uninstall -g <pkg>`       | `vlt uninstall -g <pkg>`                                         |                                                                       |
| `npm run <script>`             | `vlt run <script>`                                               | Aliases: `r`, `run-script`                                            |
| `npm test`                     | `vlt run test`                                                   | No `vlt test` shorthand                                               |
| `npm start`                    | `vlt run start`                                                  | No `vlt start` shorthand                                              |
| `npx <pkg>`                    | `vlx <pkg>`                                                      | Run remote packages                                                   |
| `npm exec <cmd>`               | `vlt exec <cmd>`                                                 | Local bins on PATH                                                    |
| `npm init`                     | `vlt init`                                                       | Creates `package.json`                                                |
| `npm pack`                     | `vlt pack`                                                       |                                                                       |
| `npm publish`                  | `vlt publish`                                                    |                                                                       |
| `npm login`                    | `vlt login`                                                      |                                                                       |
| `npm whoami`                   | `vlt whoami`                                                     |                                                                       |
| `npm ls`                       | `vlt list`                                                       | Alias: `ls`                                                           |
| `npm ls -g`                    | `vlt ls -g`                                                      |                                                                       |
| `npm query`                    | `vlt query`                                                      | Uses DSS, not CSS selectors                                           |
| `npm ci`                       | `vlt install --expect-lockfile`                                  | Strict lockfile mode                                                  |
| `npm install --ignore-scripts` | `vlt install`                                                    | Default behavior                                                      |
| `npm audit`                    | `vlt query ':malware'`                                           | More powerful; see [Security](https://docs.vlt.io/client/security.md) |
| `npm config set <key>=<val>`   | `vlt config set <key>=<val>`                                     | Writes to `vlt.json`                                                  |
| `npm overrides`                | [Graph Modifiers](https://docs.vlt.io/client/graph-modifiers.md) | DSS-based, more precise                                               |

---

## Configuration

### .npmrc → vlt.json

npm reads configuration from `.npmrc` files (INI format, multiple locations). vlt uses a single `vlt.json` file in your project root, plus an optional user-level `vlt.json` in the XDG config directory.

```ini title=".npmrc"
# .npmrc (npm)
registry=https://registry.internal.company.com/
@mycompany:registry=https://npm.mycompany.com/
save-exact=true
```

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

To create this file interactively:

```bash title="Terminal"
$ vlt config set registry=https://registry.internal.company.com/
$ vlt config set scoped-registries=@mycompany=https://npm.mycompany.com/
```

### User vs Project Config

| npm                          | vlt                           |
| ---------------------------- | ----------------------------- |
| `~/.npmrc` (user)            | XDG config dir `vlt/vlt.json` |
| `.npmrc` (project)           | `vlt.json` (project root)     |
| `$PREFIX/etc/npmrc` (global) | No global config file         |

View config locations:

```bash title="Terminal"
$ vlt config location --config=user
$ vlt config location --config=project
```

---

## Registry Configuration

vlt handles registries similarly to npm, with some additions.

### Scoped Registries

npm's scoped registries map directly:

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

```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 scope-based mapping. This is a vlt-specific feature:

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

Then reference packages explicitly:

```bash title="Terminal"
$ vlt install internal:@mycompany/utils@^2.0
```

---

## Authentication

### Tokens

npm stores auth tokens in `.npmrc`. vlt stores them in an XDG-compliant keychain file, which is less likely to be accidentally committed to source control.

```bash title="Terminal"
# npm: tokens live in .npmrc (risky if committed)
//registry.npmjs.org/:_authToken=npm_abc123

# vlt: log in interactively

$ vlt login

# vlt: or for custom registries

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

### CI Environments

```bash title="Terminal"
# npm
NPM_TOKEN=abc123 npm install

# vlt

VLT_TOKEN=abc123 vlt install
```

For non-default registries, replace non-alphanumeric characters in the URL with `_`:

```bash title="Terminal"
VLT_TOKEN_https_npm_mycompany_com=abc123 vlt install
```

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

---

## Lockfile

npm uses `package-lock.json`. vlt uses `vlt-lock.json`.

When you first run `vlt install`, vlt resolves from your `package.json` and creates `vlt-lock.json`. Your existing `package-lock.json` is not read or migrated — vlt performs a fresh resolution.

**What to do:**

1. Run `vlt install` to generate `vlt-lock.json`
2. Commit `vlt-lock.json` to source control
3. Optionally remove `package-lock.json` (or keep it if you're running both tools during a transition period)

### CI / Frozen Lockfile

```bash title="Terminal"
# npm
$ npm ci

# vlt

$ vlt install --expect-lockfile
```

---

## Install Script Protection

This is the biggest behavioral difference from npm.

**npm** runs all lifecycle scripts (`preinstall`, `install`, `postinstall`) automatically during `npm install`. This is a known supply chain attack vector.

**vlt** separates installation into two phases:

1. **`vlt install`** — Downloads and extracts packages. No scripts run.
2. **`vlt build`** — Runs lifecycle scripts selectively.

```bash title="Terminal"
# Install packages (safe — no code executes)
$ vlt install

# Run build scripts, automatically excluding packages flagged as malware

$ vlt build
```

By default, `vlt build` uses the target `:scripts:not(:built):not(:malware)`, which skips packages with known malware alerts.

You can be more selective:

```bash title="Terminal"
# Only allow specific packages to run scripts
$ vlt build --target="#esbuild, #node-gyp"

# Or allow scripts for direct dependencies only

$ vlt build --target=":root > :scripts"
```

If you need legacy npm behavior (not recommended; saved to `vlt.json`, so every later install runs all scripts):

```bash title="Terminal"
$ vlt install --allow-scripts='*'
```

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

---

## Workspaces

**Your existing npm workspaces just work.** vlt reads the `workspaces` field of the root `package.json`, and `vlt install` copies it to `vlt.json`:

```json title="package.json"
{
  "workspaces": [
    "packages/*"
  ]
}
```

Exclusion patterns such as `!packages/legacy` are honored and copied too. The `package.json` `workspaces` field is left as-is for npm. Commit `vlt.json`: `vlt ci` reads workspaces from it only.

npm 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, npm 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).

Edit `vlt.json` to use vlt's named groups, which let you run operations against a subset of your workspaces:

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

### Key Differences

- **Precedence** — if `vlt.json` has a `workspaces` field it wins outright, and the `package.json` field is ignored rather than merged. Once copied, later `package.json` edits are ignored by vlt: update `vlt.json` too.
- **Named groups** — supported only in `vlt.json`, since a `package.json` using them would be meaningless to npm.
- **Local package references** — `vlt install` rewrites a plain range that links a workspace to `workspace:*`. Kept plain ranges link only while the workspace version matches; the `:project > :workspace` modifier above links them always.

### Workspace Commands

| npm                               | vlt                               |
| --------------------------------- | --------------------------------- |
| `npm run test -w packages/a`      | `vlt run test -w packages/a`      |
| `npm run test --workspaces`       | `vlt run test --recursive`        |
| `npm install <pkg> -w packages/a` | `vlt install <pkg> -w packages/a` |

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

---

## Overrides → Graph Modifiers

npm uses `overrides` in `package.json` to force dependency versions. vlt uses [Graph Modifiers](https://docs.vlt.io/client/graph-modifiers.md) in `vlt.json`, which are powered by DSS selectors and offer more precise targeting.

```json title="package.json (npm)"
{
  "overrides": {
    "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 CSS-like specificity rules when multiple selectors match the same dependency.

---

## Migration Checklist

1. Install vlt: `npm install -g vlt`
2. In your project root, create `vlt.json` with your registry config (or use `vlt config set`)
3. Move any scoped registry config from `.npmrc` to `vlt.json`
4. Leave your `workspaces` field in `package.json` — `vlt install` copies it to `vlt.json`
5. Move `overrides` from `package.json` to `modifiers` in `vlt.json`
6. Run `vlt install` then `vlt build`; local packages referenced by plain ranges are rewritten to `workspace:*`, after which npm can no longer install the project (to keep it working, see [Workspaces](https://docs.vlt.io/client/migration/from-npm#workspaces) first)
7. Commit `vlt.json`, `vlt-lock.json` and the `package.json` files
8. Update CI scripts: replace `npm ci` with `vlt install --expect-lockfile && vlt build`
9. Update CI auth: replace `NPM_TOKEN` with `VLT_TOKEN`
10. Update any `npx` usage to `vlx`
