npm / npm/cli

[BUG] postinstall fails with e401 in Ubuntu

Open
#6,207 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 9.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

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 trying to download dependencies from Artifactory using the following environment variable:

npm_config_//server/artifactory/api/npm/npm-remote:_auth

Since NPM v9.3.1, I cannot do this in this scenario:

  1. Using Ubuntu.

  2. Having this project structure:

  • main project dir with a package.json and a "postinstall" script: cd subdir && npm install

  • subdir directory inside the main project dir with a package.json file.

When running npm install in the main project directory, the install succeeds in the main dir but fails in the subdir on this error:

npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/frogger/.npm/_logs/2023-02-27T14_33_25_467Z-debug-0.log
npm ERR! code 1
npm ERR! path /home/frogger/tests
npm ERR! command failed
npm ERR! command sh -c cd subdir && npm install
Expected Behavior

NPM install should succeed in the main directory as well as its subdirectories.

Steps To Reproduce
  1. Run git clone https://github.com/omerzi/npm-e401-issue.git
  2. Configure private registry with the auth as an environment variable: npm_config_//server/artifactory/api/npm/npm-remote:_auth
  3. Run npm install from the root dir.
Environment
  1. With this environment - Ubuntu 20.04, npm v9.5.0, node version = v16.19.0
  2. With this config -
; "project" config from /home/frogger/tests/.npmrc

; always-auth = true ; overridden by env
json = false 
; registry = "https://server/artifactory/api/npm/npm-remote" ; overridden by env

; "env" config from environment

always-auth = true 
cache = "/home/frogger/.npm" 
global-prefix = "/usr" 
init-module = "/home/frogger/.npm-init.js" 
local-prefix = "/home/frogger/tests" 
node-gyp = "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" 
prefix = "/usr" 
registry = "https://server/artifactory/api/npm/npm-remote" 
user-agent = "npm/9.5.0 node/v16.19.0 linux x64 workspaces/false" 
userconfig = "/home/frogger/.npmrc" 

; node bin location = /usr/bin/node
; node version = v16.19.0
; npm local prefix = /home/frogger/tests
; npm version = 9.5.0
; cwd = /home/frogger/tests
; HOME = /home/frogger
  1. Run npm install
  2. See error:
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/frogger/.npm/_logs/2023-02-27T14_33_25_467Z-debug-0.log
npm ERR! code 1
npm ERR! path /home/frogger/tests
npm ERR! command failed
npm ERR! command sh -c cd subdir && npm install

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Clone the linked npm-e401-issue reproduction, review its root and subdir package.json files and the environment-based .npmrc configuration, then run npm install on Ubuntu or an equivalent environment. Trace how the postinstall npm install resolves registry authentication in the nested directory; done means installation succeeds in both the root and subdir using the configured Artifactory credentials.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.