corepack icon indicating copy to clipboard operation
corepack copied to clipboard

Requests with double slash using trailing slash (/) in `COREPACK_NPM_REGISTRY`

Open MikeMcC399 opened this issue 8 months ago • 0 comments

Current behavior

If the environment variable COREPACK_NPM_REGISTRY is defined with a trailing slash, then Corepack forms URLs with requests to the registry using a double slash. For example:

COREPACK_NPM_REGISTRY=https://registry.npmjs.org/

produces a request with

https://registry.npmjs.org//pnpm

Although the official npm registry https://registry.npmjs.org/ is tolerant of such a request and does return a package, the Chinese npm mirror https://registry.npmmirror.com/ rejects the request with an HTTP 404 error. See issue https://github.com/nodejs/corepack/issues/710.

Desired behavior

Corepack > Environment Variables documentation says:

COREPACK_NPM_REGISTRY sets the registry base url used when retrieving package managers from npm. Default value is https://registry.npmjs.org

If the environment variable COREPACK_NPM_REGISTRY contains a trailing slash, then ensure that request URLs include only a single slash before the requested package manager. From the above example, that would be:

https://registry.npmjs.org/pnpm

The npm config > registry documentation specifies the default for npm as "https://registry.npmjs.org/" (with a trailing slash / character).

Corepack should also accept the implicit syntax convention used by npm.

Test code to reproduce

Ubuntu 22.04.2 LTS, Node.js 22.15.0 LTS, Corepack 0.32.0

export DEBUG=corepack
export COREPACK_NPM_REGISTRY=https://registry.npmjs.org/
rm -rf ~/.cache/node/corepack
corepack install -g pnpm@latest

Debug Logs

$ export DEBUG=corepack
export COREPACK_NPM_REGISTRY=https://registry.npmjs.org/
rm -rf ~/.cache/node/corepack
corepack install -g pnpm@latest
Installing [email protected]...
  corepack Installing [email protected] from https://registry.npmjs.org//pnpm/-/pnpm-10.10.0.tgz +0ms
  corepack Downloading to /home/mike/.cache/node/corepack/v1/corepack-4107-1615cba8.d9fdd +0ms
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +1s
  corepack No LastKnownGood version found in Corepack home. +0ms
  corepack Download and install of [email protected] is finished +0ms
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +0ms
  corepack No LastKnownGood version found in Corepack home. +0ms
  corepack Setting [email protected] as Last Known Good version +0ms
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +0ms

Workaround

When setting the environment variable COREPACK_NPM_REGISTRY remove any trailing slash / character from the registry URL.

MikeMcC399 avatar May 12 '25 10:05 MikeMcC399