Problem
When setting COREPACK_NPM_REGISTRY from npm get registry, if the registry URL ends with a trailing slash, Corepack incorrectly constructs package URLs with a double slash, resulting in HTTP 404 errors.
Steps to Reproduce
- Configure npm registry with trailing slash:
npm config set registry https://registry.example.com/artifactory/api/npm/npm/
- Export the registry to Corepack:
export COREPACK_NPM_REGISTRY=$(npm get registry)
- Try to use Corepack with yarn:
Actual Error
Internal Error: Server answered with HTTP 404 when performing the request to https://registry.example.com/artifactory/api/npm/npm//@yarnpkg/cli-dist; for troubleshooting help, see https://github.com/nodejs/corepack#troubleshooting
at fetch (/home/user/.local/share/fnm/node-versions/v24.10.0/installation/lib/node_modules/corepack/dist/lib/corepack.cjs:22051:11)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async fetchAsJson (/home/user/.local/share/fnm/node-versions/v24.10.0/installation/lib/node_modules/corepack/dist/lib/corepack.cjs:22058:20)
at async fetchAvailableVersions (/home/user/.local/share/fnm/node-versions/v24.10.0/installation/lib/node_modules/corepack/dist/lib/corepack.cjs:22001:20)
at async fetchAvailableVersions2 (/home/user/.local/share/fnm/node-versions/v24.10.0/installation/lib/node_modules/corepack/dist/lib/corepack.cjs:22139:14)
Current Behavior
Corepack attempts to fetch packages from:
https://registry.example.com/artifactory/api/npm/npm//@yarnpkg/cli-dist
Note the double slash: npm//@yarnpkg which causes a 404 error.
Expected Behavior
Corepack should normalize the URL and fetch from:
https://registry.example.com/artifactory/api/npm/npm/@yarnpkg/cli-dist
Root Cause
The issue occurs because:
npm get registry returns the registry URL with a trailing slash (e.g., https://registry.example.com/artifactory/api/npm/npm/)
- Corepack concatenates this with package paths starting with
/ (e.g., /@yarnpkg/cli-dist)
- This results in a double slash:
npm//@yarnpkg, which is an invalid URL path
Proposed Solution
Corepack should normalize the registry URL by:
- Trimming trailing slashes from
COREPACK_NPM_REGISTRY before constructing package URLs, or
- Using proper URL joining logic (e.g.,
new URL(packagePath, registryUrl)) to avoid double slashes
Workaround
Manually remove the trailing slash when setting the environment variable:
export COREPACK_NPM_REGISTRY=$(npm get registry | sed 's|/$||')
Then run:
Environment
- Node.js version: v24.10.0
- Corepack version: bundled with Node.js v24.10.0
- OS: Linux (WSL2)
Problem
When setting
COREPACK_NPM_REGISTRYfromnpm get registry, if the registry URL ends with a trailing slash, Corepack incorrectly constructs package URLs with a double slash, resulting in HTTP 404 errors.Steps to Reproduce
npm config set registry https://registry.example.com/artifactory/api/npm/npm/Actual Error
Current Behavior
Corepack attempts to fetch packages from:
Note the double slash:
npm//@yarnpkgwhich causes a 404 error.Expected Behavior
Corepack should normalize the URL and fetch from:
Root Cause
The issue occurs because:
npm get registryreturns the registry URL with a trailing slash (e.g.,https://registry.example.com/artifactory/api/npm/npm/)/(e.g.,/@yarnpkg/cli-dist)npm//@yarnpkg, which is an invalid URL pathProposed Solution
Corepack should normalize the registry URL by:
COREPACK_NPM_REGISTRYbefore constructing package URLs, ornew URL(packagePath, registryUrl)) to avoid double slashesWorkaround
Manually remove the trailing slash when setting the environment variable:
Then run:
Environment