Skip to content

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

Closed

Description

@thorseye

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.

Activity

  1. milaninfy commented on Feb 12, 2025

    @milaninfy
    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
    ⠏
  2. thorseye commented on Feb 14, 2025

    @thorseye
    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?

  3. milaninfy commented on Feb 14, 2025

    @milaninfy
    Contributor

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

  4. thorseye commented on Feb 14, 2025

    @thorseye
    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.
  5. milaninfy commented on Feb 14, 2025

    @milaninfy
    Contributor

    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"
  6. milaninfy commented on Feb 24, 2025

    @milaninfy
    Contributor

    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.

  7. thorseye commented on Feb 24, 2025

    @thorseye
    Author

    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"

    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?

  8. milaninfy commented on Feb 24, 2025

    @milaninfy
    Contributor

    by any chance are you loading any config from environment variable ?
    Provide output of npm config ls -l if 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

  9. blaurockm commented on Mar 28, 2025

    @blaurockm

    having exactly the same problem.

    And i found out: the results in the -ddd log are depending of something else:

    1. unknown url -> npm reports "GET http://unkown.url"
    2. gitlab.com with a project-endpoint and existing package -> npm reports "GET https://gitlab.com"
    3. gitlab.com with a project-endpoint and nonexisting package -> npm reports "GET https://registry.npmjs.org/"
    4. gitlab.com with an instance-endpoint and package existence doesn't matter -> npm reports "GET https://registry.npmjs.org/"

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions