[BUG] `--no-global` on the command line still installs globally when the environment or an npmrc sets `location=global`
Maintainer thường phản hồi trong vòng 2 ngày
@compiler-segfault đang làm issue này rồi.
Từ ngày 28/11/2026.
- #10377 của @compiler-segfault — đang mở
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, nodejs
- Lĩnh vực
- cli, developer-experience
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- JavaScript
- Star
- 10.3k
- Fork
- 5k
- Merge trung bình
- 4 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của npm/cli
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsCó thể đã có người làm @saruk-vedant đã nhận 7 ngày trước. Đang mởBug Needs Triage Triage Requested
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyCó thể đã có người làm @drawliin đã nhận 42 ngày trước. Đang mởcmd:delete Priority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 2 ngày
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởEngineering Priority 1
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysCó thể đã có người làm @greenlincoln05 đã nhận 63 ngày trước. Đang mởPriority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
docs: add SECURITY.md vulnerability reporting policyCó thể đã có người làm @AK-Lmn đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
flisk-sh/linux2wasm#12 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
possible bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Mintplex-Labs/anything-llm#7388 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày
-
v6: Minified bootstrap.min.css is missing header infoCó thể đã có người làm @lazerg đã nhận hôm nay. Đang mởbug build confirmed has-pr v6
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurateCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
githubnext/gh-aw-workshop#6332 ·
Maintainer thường phản hồi trong vòng 1 ngày