Skip to content

Requests with double slash using trailing slash (/) in COREPACK_NPM_REGISTRY #711

Open
@MikeMcC399

Description

@MikeMcC399

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 #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 pnpm@10.10.0...
  corepack Installing pnpm@10.10.0 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 pnpm@10.10.0 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 pnpm@10.10.0 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions