[BUG] `--no-global` on the command line still installs globally when the environment or an npmrc sets `location=global`
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, nodejs
- Ambito
- cli, developer-experience
Direzione di ricerca
Start with the global getter in lib/npm.js (around lines 445-447), which reads both global and location, then the flat location option in workspaces/config/lib/definitions/definitions.js and the global handling in lib/commands/install.js. Check how config sources are ordered in docs/lib/content/using-npm/config.md. Run the linked repro.mjs against a local checkout; done means all eleven cases report the highest-priority setting, with the global-versus-location precedence resolved consistently.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
This is not just a request to bump a dependency for a CVE
- This is not solely a request to bump a dependency for a CVE
Current Behavior
npm turns global mode on when global is true or location is global (npm.global, which npm install and npm prefix read, and location's flat option), and each of the two is read from the highest source that sets it. When they come from different sources, the lower one wins whenever it says global:
npm install --no-global, or--global=false, installs into the global prefix when the environment hasnpm_config_location=globalor an npmrc haslocation=global.npm install --location=projectinstalls into the global prefix when the environment hasnpm_config_global=true.npm installinstalls into the global prefix when an npmrc hasglobal=trueand the environmentnpm_config_location=project, or an npmrc haslocation=globaland the environmentnpm_config_global=false.
npm prefix prints the global prefix in each of them. The config docs sort npm's sources by priority: command-line flags, then environment variables, then npmrc files.
Expected Behavior
Global mode follows whichever of global and location comes from the higher-priority source, so each command above installs into the project, and npm prefix prints the project. Where only one of the two is set, nothing changes: --no-global still wins over npm_config_global=true, and --location=project over npm_config_location=global. Where the higher-priority one says global, npm still installs globally, as --global does over npm_config_location=project.
Steps To Reproduce
-
Fetch repro.mjs at the revision I ran (
curl.exein Windows PowerShell, wherecurlisInvoke-WebRequest):curl -LO https://gist.githubusercontent.com/YevheniiKotyrlo/945de540b5818e71bbe71b0a8277ed6e/raw/06ec11a803c54459afa383139a9f3c9952015b92/repro.mjs -
Run it with a Node that npm 12 runs on:
node repro.mjsWith no argument it installs the latest npm below its temporary folder, with the npm that comes with Node;
node repro.mjs <version>installs that version, andnode repro.mjs <path to bin/npm-cli.js>runs a checkout.
It runs eleven cases, each in a folder of its own holding a project, a folder dependency beside it, a global prefix and a user npmrc. Each case puts global and location on the command line, in the environment or in that npmrc, and runs npm prefix and npm install ../dependency in the project, offline, with an empty global config file, a new cache and none of the caller's npm_config_* variables. It then reports where npm prefix pointed and where the dependency went. It exits 1 when, in a case where a lower-priority source says global against a higher one, npm goes where the lower one says, 0 when every case goes where its highest setting says, and 2 when it cannot tell: a case goes anywhere else, or a step fails.
On Windows 11 with npm 12.2.3:
node v26.12.1 on win32 x64
# with the npm that comes with node, in <tmp>\npm-install
$ npm install npm@latest
installed: <tmp>\npm-install\node_modules\npm\bin\npm-cli.js
$ npm --version
12.2.3
[…]
# case 6: npm_config_location=global, --no-global; expected: the project
# in <tmp>\case-6: project/, dependency/, global-prefix/, user.npmrc (empty)
$ npm_config_location=global npm prefix --no-global
<tmp>\case-6\global-prefix
$ npm_config_location=global npm install ../dependency --no-global
added 1 package in 1s
# npm prefix: the global prefix; the dependency: in the global prefix
[…]
# where each case went (npm prefix; npm install ../dependency)
nothing set: project; project: as expected
npm_config_location=global: global prefix; global prefix: as expected
npm_config_global=true, --no-global: project; project: as expected
npm_config_location=global, --location=project: project; project: as expected
npm_config_location=project, --global: global prefix; global prefix: as expected
npm_config_location=global, --no-global: global prefix; global prefix: NOT as expected: followed the lower setting (expected: project)
npm_config_location=global, --global=false: global prefix; global prefix: NOT as expected: followed the lower setting (expected: project)
location=global in the user npmrc, --no-global: global prefix; global prefix: NOT as expected: followed the lower setting (expected: project)
npm_config_global=true, --location=project: global prefix; global prefix: NOT as expected: followed the lower setting (expected: project)
global=true in the user npmrc, npm_config_location=project: global prefix; global prefix: NOT as expected: followed the lower setting (expected: project)
location=global in the user npmrc, npm_config_global=false: global prefix; global prefix: NOT as expected: followed the lower setting (expected: project)
RESULT (exit 1): defect shows (npm 12.2.3): in 6 of the 6 cases where a lower-priority source says global against a higher one, global mode followed the lower one
The latest branch at 787f1520, run from a clone, ends the same way, and so do npm 11.20.0 and 10.2.4, 12.2.3 and that branch on Linux, in Docker's node:26 image, and npm 12.2.1 on macOS.
Environment
- npm: 12.2.3 on Windows and Linux, 12.2.1 on macOS
- Node.js: 26.12.1 on Windows and macOS, 26.13.1 on Linux
- OS Name: Windows 11 Pro 10.0.26300; Debian, in Docker's
node:26image; macOS 27.2.1 - System Model Name: a desktop PC (Windows and Linux); a MacBook Air (macOS)
- npm config:
; the reproducer runs npm with an empty global config file, a user config file of each case's own, these through the environment, and each case's own global and location
audit = false
cache = "<tmp>\npm-cache"
fund = false
offline = true
prefix = "<tmp>\case-<n>\global-prefix"
update-notifier = false
- Lingua principale
- JavaScript
- Stelle
- 10.3k
- Fork
- 5k
- Merge medio
- 4g 11h
- PR unite (30g)
- 26
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsForse già presa @saruk-vedant l’ha presa 7 giorni fa. ApertaBug Needs Triage Triage Requested
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyForse già presa @drawliin l’ha presa 42 giorni fa. Apertacmd:delete Priority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 2 giorni
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaEngineering Priority 1
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysForse già presa @greenlincoln05 l’ha presa 63 giorni fa. ApertaPriority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
possible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Mintplex-Labs/anything-llm#7388 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
v6: Minified bootstrap.min.css is missing header infoForse già presa @lazerg l’ha presa oggi. Apertabug build confirmed has-pr v6
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
githubnext/gh-aw-workshop#6332 ·
I maintainer di solito rispondono entro 1 giorno