Repository navigation
Description
package-lock.json pins every registry package's tarball URL in resolved, and npm downloads from that URL, not from the configured registry. A team that moves from Nexus or Verdaccio to Forge keeps lockfiles full of the old host:
- npm 11 and older keep downloading from the old registry for as long as it answers, which hides the problem until it is switched off.
- npm 12 refuses such a URL (
EALLOWREMOTE).
docs/npm.md says nothing about this. npm has two settings for it, and one of them behaves differently in almost every major version.
replace-registry-host
replace-registry-host (npm 8.16+) rewrites a lockfile URL onto the configured registry before the download. Below is what npm 10.9.4 and 12.2.1 fetched for the lockfile entry https://nexus.example.com/repository/npm-group/left-pad/-/left-pad-1.3.0.tgz with registry=https://forge.example.com/repository/npm-all/:
replace-registry-host |
npm 10 | npm 12 |
|---|---|---|
nexus.example.com/repository/npm-group (no scheme) |
matches nothing: downloads from Nexus | matches nothing: EALLOWREMOTE |
nexus.example.com |
…/repository/npm-all/repository/npm-group/left-pad/… (404) |
the same (404) |
nexus.example.com, with the Forge repository also named npm-group |
…/repository/npm-group/repository/npm-group/left-pad/… (404) |
…/repository/npm-group/left-pad/… ✅ |
https://nexus.example.com/repository/npm-group/ |
matches nothing: downloads from Nexus | …/repository/npm-all/left-pad/… ✅ |
npm's source (#registryResolved in workspaces/arborist/lib/arborist/reify.js) explains the rows:
- 8.16–11.2: the whole
registryURL goes in front of the lockfile URL's path. A source with a path, such as Nexus'/repository/<name>/, never works. Verdaccio's URLs, which have no path, do. - 11.3: only the host and port are swapped, and the registry's path is dropped. This breaks Forge's
/repository/<name>/too. - 11.4+: the host is swapped, and the registry's path is added unless the URL already starts with it (fix: preserve registry path when replacing a host npm/cli#8222). A Forge repository named like the Nexus one therefore works with a bare host name.
- 12.0+: a full URL, with its scheme, matches a host and path prefix and swaps that prefix for the registry's path (feat(arborist): extend replace-registry-host with URL prefix matching (#6110) npm/cli#9672). Without a scheme, the value is compared with the host name as a whole and matches nothing.
omit-lockfile-registry-resolved
With omit-lockfile-registry-resolved=true (npm 8.10+) in the project's .npmrc, npm writes no resolved for registry packages. Every client then downloads from its own registry, so clients still on the old registry and clients on Forge can share one lockfile during a transition.
- The next
npm installdrops the existingresolvedand changes no version (tried with npm 10.9.4). - An install then reads every package's packument, so it is slower.
integrityis still checked, so both registries must serve the same bytes: a package moved by the npm import (Import an npm registry's packages into a hosted npm repository #643) or bynpm publish <file>.tgz, not rebuilt.
What the guide should say
A section of docs/npm.md, "Moving from another registry", with:
- why lockfiles keep the old host, and how to see where npm downloads from. npm reuses a cached tarball by its integrity, whatever its URL, so the cache and
node_modulesgo first:npm cache clean --force,rm -rf node_modules, thennpm ci --loglevel=http. - the cutover that needs no client setting. Forge serves npm repositories at Nexus' URLs (
/repository/<name>/, Nexus-compatible repository URLs: serve every format's repositories under /repository/<repo>/ #311), so a Forge repository named like the Nexus one, with Nexus' host name moved to Forge, keeps every lockfile URL valid. Only the.npmrccredentials change. -
replace-registry-hostper npm version, with the table above and the pitfall of a value without a scheme. -
omit-lockfile-registry-resolvedfor a transition in which some clients stay on the old registry, and the byte-identical tarballs it needs. - which other clients this concerns: Yarn 1's lockfile carries tarball URLs, while pnpm's and Yarn 2+'s carry none for a registry package (to be confirmed while writing it).
- Changelog fragment:
docs.
Activity