[BUG] `--no-global` on the command line still installs globally when the environment or an npmrc sets `location=global`
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, nodejs
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- JavaScript
- スター
- 10.3k
- フォーク
- 5k
- 平均マージ
- 4日 11時間
- マージ済み PR(30日)
- 26
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
npm/cli のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endings対応中かも @saruk-vedant が 7 日前に担当しました。 オープンBug Needs Triage Triage Requested
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
[BUG] npm pkg delete removes the first array item for a nonexistent property対応中かも @drawliin が 42 日前に担当しました。 オープンcmd:delete Priority 3
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 2 日以内に返信
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings logged再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンEngineering Priority 1
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 2 日以内に返信
-
`npm audit signatures` does not report how many packages it skipped for want of registry keys対応中かも @greenlincoln05 が 63 日前に担当しました。 オープンPriority 3
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
docs: add SECURITY.md vulnerability reporting policy対応中かも @AK-Lmn が今日担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
flisk-sh/linux2wasm#12 ·
メンテナーはふだん 1 日以内に返信
-
possible bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Mintplex-Labs/anything-llm#7388 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 60/100
メンテナーはふだん 1 日以内に返信
-
v6: Minified bootstrap.min.css is missing header info対応中かも @lazerg が今日担当しました。 オープンbug build confirmed has-pr v6
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
githubnext/gh-aw-workshop#6332 ·
メンテナーはふだん 1 日以内に返信