Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

npm

deps-npm provides full LSP support for Node.js/JavaScript projects using npm, pnpm, or Yarn — all three read the same package.json format.

Basics

Manifest filepackage.json; pnpm-workspace.yaml for catalog entries
Lock file (in-use version)package-lock.json (versions 2 and 3), pnpm-lock.yaml, yarn.lock (Yarn v1 and Berry) or bun.lock (Bun 1.2+)
Registrynpm registry — packument API (registry.npmjs.org/{package}) for versions, search API (registry.npmjs.org/-/v1/search) for package-name search
Version syntaxnode-semver ranges: ^, ~, =, <, <=, >, >=, *

deps-npm parses dependencies, devDependencies, peerDependencies, and optionalDependencies, tracking each entry’s exact key/value byte span for accurate hover/diagnostic/completion positioning.

{
  "dependencies": {
    "express": "^4.18.2"
  }
}

Hovering the version string shows the latest npm release and whether ^4.18.2 is satisfied; an outdated dependency gets an inlay hint and a diagnostic with an “Update to latest version” code action. Typing a version prefix completes from the real, live version list; typing a new dependency name searches the npm registry. watched_configs covers .npmrc and pnpm-workspace.yaml — editing either one externally (e.g. git checkout) triggers a reparse of every open package.json so pushed diagnostics stay current without waiting for the next in-editor edit.

Custom/Private Registries

An npm dependency whose scope (via @scope:registry=) or whose workspace (via a top-level registry= override) resolves to a private/custom registry through .npmrc gets the same hover/diagnostic/completion value a registry.npmjs.org dependency gets — instead of showing no version data, or (before this feature) silently checking the wrong (public) registry.

Resolution: .npmrc is read from a two-tier hierarchy — the project tier (walked from the opened package.json’s directory up to the filesystem root, closest directory winning; a deliberate superset of npm’s own project-root-only read, chosen for monorepo ergonomics and mirroring Cargo’s .cargo/config.toml discovery — see Cargo) and the user tier (~/.npmrc). The global tier ($PREFIX/etc/npmrc) is not read. A @scope:registry= entry always takes precedence over a top-level registry= override for a dependency in that scope. Scope keys are matched byte-exact, with no case folding, matching npm’s own lookup. A ${VAR}-style placeholder in either key’s value is expanded from this LSP server’s own process environment; an undefined variable makes the whole entry invalid (same outcome as an invalid URL, below). deps-lsp watches .npmrc for external changes (e.g. a git checkout) and reparses every open package.json to refresh pushed diagnostics, rather than waiting for that document’s own next edit.

Authentication: phase 1 carries no authentication at all. _authToken, _auth, _password, _authIdent, always-auth, and every //<host>/:_* scoped-credential key are never parsed, held in memory, logged, or transmitted — every alternate-registry request is unauthenticated. A follow-up spec is required before any credential is wired up.

Fail-closed on misconfiguration: a registry=/@scope:registry= value that is not a well-formed https:// URL, carries userinfo, or is blocked by the reachability policy below shows no version data for the affected dependency — never a silent fallback to registry.npmjs.org, matching Cargo’s equivalent guarantee for a misconfigured registry alias.

Vulnerability scanning. A dependency routed by a top-level registry= entry (an Artifactory, Nexus or Verdaccio proxy, or a mirror such as registry.npmmirror.com) is not sent to OSV, because the registry cannot be verified as a mirror of npmjs. The skip is reported, not silent: deps-cli check prints one stderr note with the count, and hover shows “Vulnerability data not checked”. An invalid top-level registry= entry is counted in the note too, but hover shows no footer for it because its registry cannot be resolved. Dependencies routed by an @scope:registry= entry are treated as private and are skipped silently. An explicit registry=https://registry.npmjs.org/ is the public registry itself: it is scanned like a dependency with no .npmrc at all and produces no note.

Proxies. A registry your user ~/.npmrc declares (and a project .npmrc URL equal to one) is an operator-owned registry: it follows your system proxy like the public registries. Registries only a project .npmrc declares stay workspace-guarded and direct by default (see Proxies and guarded registry traffic).

Reachability policy: a URL equal to one your ~/.npmrc declares (after ${VAR} expansion), whichever .npmrc declared it in this workspace, is trusted and ignores registries.workspace_registries, including "off"; it may resolve to a private address under "public_only". Equality is per URL, so the same host with another path is not trusted. Every other URL is governed by the setting documented in Cargo, including its connect-time message for a host that resolves to a blocked address. Setting registries.workspace_registries to "all" for npm’s benefit also widens it for Cargo, and vice versa; either way only the hosts in DEPS_LSP_PRIVATE_REGISTRY_HOSTS become reachable (see Configuration).

A change to a .npmrc or pnpm-workspace.yaml reparses only the open manifests in that file’s directory and below, the ones the ancestor walk can reach. A change to the user-level ~/.npmrc (a .npmrc directly in your home directory) reparses every open npm and Deno document, wherever it lives.

Known limitations:

  • Package-name completion (typing a brand-new dependency) always searches registry.npmjs.org, even for a scope resolved to a private registry — the string being searched is a prefix the user typed into the name field, not a resolved private dependency name, so this is safe but not registry-aware.
  • A dependency resolved to a private registry drops out of OSV vulnerability scanning and loses its npmjs.com hover link (an advisory or link keyed to the public package name does not apply to a same-named private package) and its relative-age (“published N days ago”) hover suffix.
  • .yarnrc/.yarnrc.yml (Yarn Berry’s own config format) are not read for registry routing, only for Yarn’s release-age gate (see below); a standard .npmrc present in the workspace is still honored either way. pnpm’s own pnpm-workspace.yaml catalog extension is read — see below.

Lock Files

When several lock files sit next to a manifest, the first one in this order wins: package-lock.json, then pnpm-lock.yaml, then yarn.lock, then bun.lock. A lock file that loses is logged at debug level.

yarn.lock is read for both Yarn generations, so hover, inlay hints and OSV matching use the version Yarn actually installed:

  • Yarn v1 (# yarn lockfile v1): one entry per header line. A header lists at most 256 package names; anything beyond is ignored.
  • Yarn Berry (YAML with a top-level __metadata): supported for __metadata.version 4 to 8, a newer or older lock file is rejected with a parse error rather than guessed at. A patch: entry resolves to the version it patches, a ::__archiveUrl= suffix is stripped from the version, and workspace: and link: entries are skipped.

bun.lock (the text lock file written by Bun 1.2 and later, JSONC with trailing commas) is read for lockfileVersion 0 to 3; an absent, non-integer or newer version is rejected with a parse error naming the value rather than guessed at. An empty or whitespace-only file yields no resolved versions. The version comes from each entry’s name@version label, so an npm: alias resolves under the real registry name and a nested install (is-odd/is-number) records its own version next to the hoisted one. workspace:, link:, file:, git and tarball entries are skipped, because Bun records no version for them. The binary bun.lockb is not read; run bun install --save-text-lockfile to get a bun.lock.

Several lock entries for one package

A lock file can hold more than one entry for a package that satisfies a manifest requirement (a workspace member pinning an older copy, a transitive consumer’s own range, a foo/minimist nested install). The lock file does not say which copy was installed for your dependency, so the version shown as in use is the highest satisfying entry, and every other satisfying entry is scanned for advisories as well. An advisory that affects only another locked copy is reported as also locked at <version>; see Lock alternatives.

Each lock format attributes its entries to a workspace member as far as it records them, and the entry belonging to the package.json you are looking at is preferred:

  • package-lock.json knows where each copy lives. A copy nested under another package (node_modules/foo/node_modules/minimist) belongs to that package and is not a candidate for your dependency. The root node_modules/<name> entry belongs to the root, and <member>/node_modules/<name> to that workspace member; a member’s own entry wins over another member’s. A workspace folder entry (packages/a) has no owner.
  • pnpm-lock.yaml lists the resolved version per importer, so a member’s own importer entry is used; a package.json that is not a registered importer falls back to the nearest ancestor importer, then to the highest satisfying entry.
  • bun.lock installs a member’s own copy under <workspace name>/<name> and hoisted copies under the bare name (the root). A copy under any other prefix is nested under another package and is demoted exactly like package-lock.json’s: it is no longer reported as also locked at while a hoisted entry of the same name exists.
  • yarn.lock (v1 and Berry) records which declared requirement each entry resolves, so the entry that lists your requirement text verbatim (^1.2.0, compared as written) is used.

When the preferred entry does not satisfy the requirement, the highest satisfying entry is used instead, and every other satisfying entry stays an also locked at alternative.

Release-Age Windows

When the project’s package manager holds back young releases, a latest inside that window is explained, never written: hover and check name the setting and when the version becomes eligible, and deps-cli update skips it (exit 0). Nothing older is proposed in its place, and a version already in the lock file stays eligible. Which manager applies is decided by the lock file the project resolves with (package-lock.json, pnpm-lock.yaml, bun.lock/bun.lockb, yarn.lock); without one, a pnpm-workspace.yaml selects pnpm, a bunfig.toml selects Bun, otherwise npm. Only that manager’s own file in the project root (the directory of the lock file, else the manifest’s directory) is read; your home directory and environment variables never are.

ManagerFileSettingUnit
npm.npmrcmin-release-age, or before (an absolute cutoff that wins when both are set)days; RFC 3339 or YYYY-MM-DD
pnpmpnpm-workspace.yamlminimumReleaseAge (off when minimumReleaseAgeStrict: false)minutes
Bunbunfig.toml[install] minimumReleaseAgeseconds
Yarn.yarnrc.ymlnpmMinimalAgeGate, and npmScopes.<scope>.npmMinimalAgeGateminutes when bare, else <n>ms/s/m/h/d/w (fractions allowed)

pnpm’s and Yarn’s built-in global defaults are never assumed: only a declared value applies. Yarn’s gate needs Yarn 4.10 or newer, and its per-scope keys Yarn 4.17 or newer. A per-scope key under any npmScopes.<scope> entry proves 4.17 or newer (older Yarn rejects the key name, whatever its value); only then does a scoped package whose scope entry lacks the key get Yarn’s own 1 day default (shown as (Yarn default)) instead of the global value. Scopes without an entry use the global npmMinimalAgeGate; 0 turns a window off. npmPreapprovedPackages exempts by name or * glob; an entry with a version range discards the whole list. Exemptions (min-release-age-exclude, minimumReleaseAgeExclude, minimumReleaseAgeExcludes) accept names, name@version and * wildcards (segment-scoped for npm); an entry the server cannot interpret exactly discards the whole list, so the window holds more rather than less. A malformed value (a fraction, a negative number, text) is ignored with a warning.

Publish times are fetched only when a window applies: the server then reads the package’s full document even with freshness.enabled = false, within the same cache, timeout and size limits as the freshness signal, and through the same network policy as the version list. If a registry omits publish times or the fetch times out, the window does not apply to that package. Because those versions are now dated, a deprecated security-fix target is no longer steered onto a latest that is younger than the default release cooldown (3 days), exactly as for Cargo. A project without a window sends exactly the requests it sent before. freshness.honor_native_cooldown = false ignores all of it.

Non-Registry Dependency Sources

A dependency declared against a git repository, a local filesystem path, or a workspace sibling is classified as such instead of defaulting to registry.npmjs.org — this covers git+ssh:///git+https:///git:// URLs, a bare HTTPS URL to a known git host (GitHub/GitLab/Bitbucket) ending in .git, github:/gitlab:/bitbucket:/gist: shorthand (owner/repo[#ref]), a direct tarball URL, file:/link:/portal:-prefixed and bare local paths (./, ../, ~/, or a Windows drive letter), and workspace: protocol dependencies. A dependency resolved this way is never sent to the registry, drops its public-registry hover link, and is excluded from OSV vulnerability scanning against the public package name — matching the treatment Cargo already gives a git =/path = dependency (resolves #1202).

npm: Alias Resolution

npm/pnpm/yarn let a package.json dependency install under a different local import name than its registry package, via the npm: protocol prefix: "my-react": "npm:react@^18.0.0" — my-react is the local key, react is the real package to resolve, ^18.0.0 is its version requirement. Hover, completion, diagnostics, code lens, inlay hints, .npmrc scoped-registry routing, and OSV vulnerability lookups all resolve against the real package name (react), while the local alias key stays the position anchor for hover/diagnostic ranges in the editor (resolves #654). A scoped real package name ("my-pkg": "npm:@scope/pkg@^1.0.0") is supported the same way. A dist-tag alias ("npm:react@beta") or one with no version at all ("npm:react") resolves as an existence check (equivalent to a bare "*" requirement) rather than a specific version comparison.

Code actions/lens are not offered for an npm:-aliased dependency: the manifest text at the version position is the whole npm:pkg@range literal, not just the range, so an automated rewrite would need to preserve the alias prefix — not yet implemented. This is a deliberate, safe degradation (no version data is lost, only the one-click fix), not a bug.

Known limitation: the pnpm-catalog combination form (npm:<pkg>@catalog:<name>) is not detected — see pnpm Catalogs below.

pnpm Catalogs

A package.json dependency declared as "catalog:" (the default catalog) or "catalog:<name>" (a named catalog) resolves against the nearest-ancestor pnpm-workspace.yaml’s catalog:/catalogs.<name>: map — the same hover/diagnostic/completion/inlay-hint experience a literal semver range gets, instead of an unresolvable raw string.

Resolution: the nearest pnpm-workspace.yaml found walking up from the package.json’s directory wins (matching pnpm’s own find-workspace-dir single-root-per-tree behavior — nested/multiple workspace roots are not searched further). catalog: and catalog:default are equivalent references to the default catalog, which may be defined either as a top-level catalog: block or a catalogs.default: section (but never both — see below). deps-lsp watches pnpm-workspace.yaml for external changes and reparses every open package.json to refresh pushed diagnostics, rather than waiting for that document’s own next edit.

Fail-closed, never destructive: whenever a catalog: specifier does not resolve to a parseable semver range — no pnpm-workspace.yaml found, the file is malformed, the referenced catalog or entry doesn’t exist, or the entry’s value isn’t a semver range (workspace:*, a git URL) — the dependency’s version requirement is left unset while hover still renders an explanatory message. This is a deliberate correctness guarantee, not a missing feature: an unresolved catalog specifier must never be treated as a valid semver range, since that would let the “Update all outdated dependencies” quick-fix silently overwrite "react": "catalog:" with a literal version, destroying the catalog reference.

Update edits keep the operator: an update to ^16.0.0 writes ^19.3.1, and ~ and = are kept the same way, and a bare or tilde partial version (16, 16.1, ~16) keeps its precision (~16 with a latest of 19.3.1 becomes ~19). Other range forms become the exact version. Prerelease versions are not offered unless the registry’s latest is a prerelease or the dependency is already on one.

A catalog entry whose value exceeds a length cap (256 bytes) is rejected before it is even parsed as a semver range, closing a resource-exhaustion vector in an unbounded pnpm-workspace.yaml entry — unlike the other fail-closed cases above, this one does surface a diagnostic, since no real catalog entry approaches this length.

Both a top-level catalog: block and a catalogs.default: section present is treated as unresolvable for every catalog: specifier in the workspace (not only default-catalog references) — matching pnpm’s own checkDefaultCatalogIsDefinedOnce, which rejects the whole workspace manifest in this situation before returning any catalog map at all; this deliberately never per-key-merges the two sections.

Known limitations:

  • The npm:<pkg>@catalog:<name> combination form (an npm: alias whose version is itself a catalog reference) is not detected — the base npm: alias form (no catalog combination) is resolved, see npm: Alias Resolution above.
  • A catalog entry whose value isn’t a scalar string (e.g. a nested mapping) gets its own distinct “not a version string” message rather than being validated against pnpm’s own schema further.
  • The binary bun.lockb is not read for in-use/resolved-version detection; only the text bun.lock is (see Lock Files).
  • A package.json that is not a registered pnpm importer inherits its nearest ancestor importer’s entries (the same walk-up node_modules resolution uses), not an arbitrary importer’s.

Editing pnpm-workspace.yaml Catalog Entries

Catalog versions live in pnpm-workspace.yaml, so that is where you edit them. Open the file and every registry-resolvable entry under catalog: or catalogs.<name>: gets the same inlay hints, diagnostics, hover, completion, code actions and code lens as a package.json dependency, positioned on the entry’s own version text:

packages:
  - "packages/*"

catalog:
  react: ^16.0.0        # outdated hint and diagnostic on ^16.0.0
  lodash: 4.17.0

catalogs:
  legacy:
    left-pad: ^1.0.0
  • Outdated, deprecated, yanked, vulnerable, unknown and unsatisfiable findings use the same wording, severities and version-comparison rules as package.json.
  • Update code actions replace only the version text of that entry and keep its quoting style (react: "^16.0.0" stays quoted). One edit updates every workspace package that references the catalog. “Update all outdated” covers every catalog in the file.
  • Completion offers package names on the key and registry versions on the value.
  • In-use versions come from the root pnpm-lock.yaml, found by walking up from the YAML file.
  • catalogs.default: is read as the default catalog, exactly like a top-level catalog:. A catalog named default therefore can never be confused with another named catalog.

An entry that is not a registry range is classified like its package.json counterpart: an npm: alias, a git URL or a file: path is not looked up, and an entry whose value is a mapping is skipped without affecting the rest of the file. A placeholder such as ${REACT_VERSION} and a YAML alias (react: *r) get findings only; no rewrite is offered because there is no literal text to replace safely. The overrides: section is read separately (see pnpm Overrides and Catalog Usage); other sections of the file are ignored.

Duplicate default catalog

pnpm rejects a workspace that defines both a top-level catalog: and catalogs.default:. deps-lsp reports one error, pnpm-duplicate-default-catalog, anchored on the catalogs.default key, and still shows findings for the entries of both sections. In deps-cli the finding is classified as other and is not part of the default --fail-on set; gate on it with --fail-on other.

How the two files relate

An outdated catalog entry is a finding in two places: on the entry in pnpm-workspace.yaml, and on each "react": "catalog:" reference in a package.json. To make this readable, the reference keeps its finding, appends (set in pnpm-workspace.yaml, catalog default) to the message and links to the entry through the diagnostic’s related information. No rewrite is offered on the reference, since rewriting it would replace the catalog specifier with a literal version. If three packages reference the same entry, the YAML file still reports it once.

Saving pnpm-workspace.yaml refreshes the diagnostics of open package.json files that reference it. The refresh reads the saved file, so an edit you have not saved yet does not propagate, and the related-information location can be stale until the next save.

deps-cli check and deps-cli update process pnpm-workspace.yaml like any other manifest. An outdated entry is therefore reported once from the YAML file and once from each referencing package.json, and --fail-on counts each report.

Connecting your editor

The server handles the file; your editor must send it to deps-lsp. In Neovim, yaml is already in the filetypes list shown in Editor Setup. In VS Code, add pnpm-workspace.yaml to your client’s document selector (for example { "language": "yaml", "pattern": "**/pnpm-workspace.yaml" }). The Zed extension does not associate the file with deps-lsp yet, because other language servers also claim the YAML language there.

A syntactically invalid file produces no entry-level findings while you type, and the same size and nesting limits as for other YAML manifests apply.

pnpm Overrides and Catalog Usage

Entries of the overrides: section in pnpm-workspace.yaml are dependencies like catalog entries: they get hints, diagnostics and update actions, and deps-cli check and update treat them as targets. A selector key such as bar>foo@<2 (parent chain, then name@range) is split by pnpm’s rule: a > separates parents only when it does not follow a space, | or @, so axios@>=0.8.1 <0.28.0 stays one selector. Values -, $ref and catalog: produce no dependency. Known limitation: when the lock file holds a single version of an override target that does not satisfy the override range, that version is shown as is.

Hovering a catalog entry shows Used by N workspace packages. The count comes from a bounded walk of the packages: globs (no .., absolute paths or symlinks, node_modules, target, dist, vendor and dot directories skipped; at most 20,000 directory entries, 1,000 package.json files, 1 MiB per manifest and 2 seconds). When a bound is reached the hover says at least N. The result is cached for 30 seconds and refreshed in the background, so hover never waits for a stale index.

Package Name Validation

When a dependency in package.json fails to resolve against the npm registry, the diagnostic distinguishes between two cases instead of always reporting “Unknown package”:

  • Invalid package name '<name>': <reason> — the name itself violates npm’s own naming rules (e.g. it starts with ./_, exceeds 214 characters, contains a character outside npm’s URL-friendly set, or is a reserved name like node_modules).
  • Unknown package '<name>' — the name is syntactically valid but was not found in the registry (typo, private/unpublished package, etc.).

The check is deliberately permissive: uppercase names are still accepted (npm only warns on those for legacy packages, never rejects), and it accepts every character npm’s own encodeURIComponent(segment) === segment predicate accepts, including ! ' ( ) * - . _ ~ — not just alphanumerics and hyphens.

Release-Freshness Coverage

npm’s freshness signal (gated by freshness.enabled, default true) issues an entire additional full-packument fetch per package, not a marginal delta — the abbreviated packument get_versions already fetches carries no publish dates, so freshness attaches a separately-fetched, TTL’d (1 hour) {version: date} map derived from the full packument’s time field instead. npm is the one ecosystem in this project where freshness.enabled: false genuinely removes a whole request per hover/completion round, not just a conditional revalidation. See NuGet for the other half of this shared signal.