Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] npm view does not respect registry for @scope in .npmrc #8103

Open
2 tasks done
thorseye opened this issue Feb 12, 2025 · 5 comments
Open
2 tasks done

[BUG] npm view does not respect registry for @scope in .npmrc #8103

thorseye opened this issue Feb 12, 2025 · 5 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@thorseye
Copy link

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-yet

it 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.
@thorseye thorseye added Bug thing that needs fixing Needs Triage needs review for next steps labels Feb 12, 2025
@milaninfy
Copy link
Contributor

From config I could see scoped registry is configured at project level .npmrc, so whenever you are running npm view @scope/pkg from same project where your .npmrc resides then it should pick up the registry value.

As you can check the logs it's picking up scoped registry config from .npmrc file.

~/workarea/rep $ npm view @myscope/not-published-yet -ddd
npm verbose cli /Users/milaninfy/.nvm/versions/node/v22.13.1/bin/node /Users/milaninfy/.nvm/versions/node/v22.13.1/bin/npm
npm info using npm@11.1.0
npm info using node@v22.13.1
npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.13.1/lib/node_modules/npm/npmrc
npm silly config load:file:/Users/milaninfy/workarea/rep/.npmrc
npm silly config load:file:/Users/milaninfy/.npmrc
npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.13.1/etc/npmrc
npm verbose title npm view @myscope/not-published-yet
npm verbose argv "view" "@myscope/not-published-yet" "--loglevel" "silly"
npm verbose logfile logs-max:10 dir:/Users/milaninfy/.npm/_logs/2025-02-12T15_00_22_946Z-
npm verbose logfile /Users/milaninfy/.npm/_logs/2025-02-12T15_00_22_946Z-debug-0.log
npm silly logfile start cleaning logs, removing 3 files
npm silly logfile done cleaning log files
npm http fetch GET https://gitlab.internal.com/api/v4/packages/npm/@myscope%2fnot-published-yet attempt 1 failed with ERR_SSL_WRONG_VERSION_NUMBER
npm http fetch GET https://gitlab.internal.com/api/v4/packages/npm/@myscope%2fnot-published-yet attempt 2 failed with ERR_SSL_WRONG_VERSION_NUMBER
⠏

@thorseye
Copy link
Author

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:

$ npm view @myscope/not-published-yet -ddd
npm verbose cli /usr/bin/node /home/theuser/.npm/bin/npm
npm info using npm@11.1.0
npm info using node@v20.18.2
npm silly config load:file:/home/theuser/.npm/lib/node_modules/npm/npmrc
npm silly config load:file:/tmp/npm-scope/.npmrc
npm silly config load:file:/home/theuser/.npmrc
npm silly config load:file:/etc/npmrc
npm verbose title npm view @myscope/not-published-yet
npm verbose argv "view" "@myscope/not-published-yet" "--loglevel" "silly"
npm verbose logfile logs-max:10 dir:/home/theuser/.npm/cache/_logs/2025-02-14T11_49_06_307Z-
npm verbose logfile /home/theuser/.npm/cache/_logs/2025-02-14T11_49_06_307Z-debug-0.log
npm silly logfile start cleaning logs, removing 1 files
npm silly logfile done cleaning log files
npm http fetch GET 404 https://registry.npmjs.org/@myscope/not-published-yet 207ms (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 /tmp/npm-scope
npm verbose os Linux 5.14.0-503.22.1.el9_5.x86_64
npm verbose node v20.18.2
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-14T11_49_06_307Z-debug-0.log

I don't see what could differ here. What am I missing?

@milaninfy
Copy link
Contributor

Can you check the location of your .npmrc and from where you are running your command ?

@thorseye
Copy link
Author

Currently, I've put the .npmrc with the @myscope config in an empty folder, and run the command from there. I get the same behaviour if I put the config in my ~/.npmrc instead, 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-scope
$ ls -lAo
total 4
-rw-rw-r--. 1 theuser 62 Feb 14 12:48 .npmrc
$ cat .npmrc 
@myscope:registry=https://gitlab.internal.com/api/v4/packages/npm
$ npm config ls
; "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"
init.author = "Jonas Thoursie"
prefix = "/home/theuser/.npm"

; "project" config from /tmp/npm-scope/.npmrc

@myscope:registry = "https://gitlab.internal.com/api/v4/packages/npm"

; node bin location = /usr/bin/node
; node version = v20.18.2
; npm local prefix = /tmp/npm-scope
; npm version = 11.1.0
; cwd = /tmp/npm-scope
; HOME = /home/theuser
; Run `npm config ls -l` to show all defaults.

@milaninfy
Copy link
Contributor

milaninfy commented Feb 14, 2025

If you are running a command where your .npmrc is located then it should pick up the registry value mentioned in .npmrc, if your .npmrc located at user level then it should work from anywhere for that user.

~/workarea/rep $ npm view @scope/somepkg -dddd
npm info using npm@11.1.0
npm info using node@v22.13.1
npm http fetch GET http://www.non-existant-registry.npmjs.com/@scope%2fsomepkg attempt 1 failed with ENOTFOUND
⠴^C
~/workarea/rep $ cat .npmrc
@scope:registry="http://www.non-existant-registry.npmjs.com"

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

2 participants