Repository navigation
[BUG] npm view does not respect registry for @scope in .npmrc #8103
Copy link
Copy link
Closed
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next steps
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
I'm using Gitlab as a private npm registry, and got an unexpected log output from npm that is confusing me.
When running:
npm view @myscope/not-published-yetit seems like npm is not respecting the registry that is defined for @myscope in .npmrc (see example below).
Expected Behavior
I expected that npm would check in the specified registry (still return a 404 though).
Steps To Reproduce
In my .npmrc, I've got this:
//gitlab.internal.com/api/v4/packages/npm/:_authToken = (protected)
@myscope:registry=https://gitlab.internal.com/api/v4/packages/npm
When running npm view for a package that is not yet published to the internal registry (neither to the public npm registry), it seems like npm is not respecting the registry for the specified scope, i.e:
$ npm view @myscope/not-published-yet --verbose
npm verbose cli /usr/bin/node /home/theuser/.npm/bin/npm
npm info using npm@11.1.0
npm info using node@v20.17.0
npm verbose title npm view @myscope/not-published-yet
npm verbose argv "view" "@myscope/not-published-yet" "--loglevel" "verbose"
npm verbose logfile logs-max:10 dir:/home/theuser/.npm/cache/_logs/2025-02-12T07_48_15_403Z-
npm verbose logfile /home/theuser/.npm/cache/_logs/2025-02-12T07_48_15_403Z-debug-0.log
npm http fetch GET 404 https://registry.npmjs.org/@myscope/not-published-yet 791ms (cache skip)
npm verbose stack HttpErrorGeneral: 404 Not Found - GET https://registry.npmjs.org/@myscope/not-published-yet - Not found
npm verbose stack at /home/theuser/.npm/lib/node_modules/npm/node_modules/npm-registry-fetch/lib/check-response.js:103:15
npm verbose stack at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
npm verbose stack at async RegistryFetcher.packument (/home/theuser/.npm/lib/node_modules/npm/node_modules/pacote/lib/registry.js:90:19)
npm verbose stack at async #getData (/home/theuser/.npm/lib/node_modules/npm/lib/commands/view.js:135:20)
npm verbose stack at async #viewPackage (/home/theuser/.npm/lib/node_modules/npm/lib/commands/view.js:112:28)
npm verbose stack at async View.exec (/home/theuser/.npm/lib/node_modules/npm/lib/commands/view.js:70:5)
npm verbose stack at async Npm.exec (/home/theuser/.npm/lib/node_modules/npm/lib/npm.js:207:9)
npm verbose stack at async module.exports (/home/theuser/.npm/lib/node_modules/npm/lib/cli/entry.js:67:5)
npm verbose statusCode 404
npm verbose pkgid @myscope/not-published-yet@*
npm error code E404
npm error 404 Not Found - GET https://registry.npmjs.org/@myscope/not-published-yet - Not found
npm error 404
npm error 404 '@myscope/not-published-yet@*' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm verbose cwd /home/theuser/dev/flyg/llf/llf-ws
npm verbose os Linux 5.14.0-503.22.1.el9_5.x86_64
npm verbose node v20.17.0
npm verbose npm v11.1.0
npm verbose exit 1
npm verbose code 1
npm error A complete log of this run can be found in: /home/theuser/.npm/cache/_logs/2025-02-12T07_48_15_403Z-debug-0.log
Environment
- npm: 11.1.0
- Node.js: v20.17.0
- OS Name: Red Hat Enterprise Linux 9.5 (Plow)
- System Model Name: Lenovo ThinkPad T14 Gen 4
- npm config:
; "global" config from /etc/npmrc
; prefix = "/usr/local" ; overridden by user
python = "/usr/bin/python3"
; "user" config from /home/theuser/.npmrc
//gitlab.internal.com/api/v4/packages/npm/:_authToken = (protected)
cache = "/home/theuser/.npm/cache"
prefix = "/home/theuser/.npm"
; "project" config from /home/theuser/path/to/project/.npmrc
@myscope:registry = "https://gitlab.internal.com/api/v4/packages/npm"
; node bin location = /usr/bin/node
; node version = v20.17.0
; npm local prefix = /home/theuser/path/to/project
; npm version = 11.1.0
; cwd = /home/theuser/path/to/project
; HOME = /home/theuser
; Run `npm config ls -l` to show all defaults.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next steps
Activity
milaninfy commentedon Feb 12, 2025
From config I could see scoped registry is configured at project level
.npmrc, so whenever you are runningnpm view @scope/pkgfrom same project where your.npmrcresides then it should pick up the registry value.As you can check the logs it's picking up scoped registry config from .npmrc file.
thorseye commentedon Feb 14, 2025
I am not getting the same behaviour as you @milaninfy . If I run the same command, the output clearly shows that npm is trying to find the package in https://registry.npmjs.org:
I don't see what could differ here. What am I missing?
milaninfy commentedon Feb 14, 2025
Can you check the location of your
.npmrcand from where you are running your command ?thorseye commentedon Feb 14, 2025
Currently, I've put the
.npmrcwith the@myscopeconfig in an empty folder, and run the command from there. I get the same behaviour if I put the config in my~/.npmrcinstead, and run it from somewhere else...(username and internal gitlab url is modified to not expose things that should not be exposed)
$ pwd /tmp/npm-scopemilaninfy commentedon Feb 14, 2025
If you are running a command where your
.npmrcis located then it should pick up the registry value mentioned in.npmrc, if your.npmrclocated at user level then it should work from anywhere for that user.milaninfy commentedon Feb 24, 2025
Closing due to inactivity. If this is still a problem please feel free to reopen this issue, or create a new issue w/ steps to reproduce.
thorseye commentedon Feb 24, 2025
Yes, this is what I would’ve expected as well. But as I tried to explain, this is not the case. I don’t know how to elaborate this further. I believe that this is a bug and I’ve provided steps for reproduction.
I get that it’s not priority for you. Maybe I could debug it and try to fix it myself if you give me a hint on where to look?
milaninfy commentedon Feb 24, 2025
by any chance are you loading any config from environment variable ?
Provide output of
npm config ls -lif possible from your project dir?Configs are loaded from this package if you want to explore at your end.
https://github.com/npm/cli/tree/latest/workspaces/config
blaurockm commentedon Mar 28, 2025
having exactly the same problem.
And i found out: the results in the -ddd log are depending of something else:
In every case i used ~/.npmrc as a config file, just changed the scope to URL mapping.
somehow there is a bug in npm: "-ddd" logs the wrong URL even it takes the correct one.
(see case 2 and 3 from above)
I would expect the npm-log would exactly show the URL it takes to resolve the package. The npm-output should not depend on the existence of the package or something else going wrong. In case 3 i would expect the URL from the scope to config-mapping, not the generic URL.
This is especially annoying in case 4 because you don't know where to search and suspect the culprit in npm.