[BUG] `npm install --offline` still sends requests to the registry: the update check asks it for npm
维护者通常 2 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- javascript, nodejs
调研方向
The update check lives in lib/cli/update-notifier.js, which fetches the manifest with cache: false and skips only on update-notifier off, global updates and CI, so offline is not honoured. Read that file alongside node_modules/npm-registry-fetch/lib/index.js to see how the offline setting reaches the fetch. Done means npm install --offline sends no request to the registry (or only cache reads), while online behaviour is unchanged; note that pull request #10374 is already open against this issue.
由索引模型根据 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
With --offline, npm still sends requests to the registry. npm install --offline in a project with no dependencies and a new cache sends GET /npm to the registry: the update check asking for the latest npm. offline is described as "Force offline mode: no network requests will be done during install."
The check fetches the manifest with cache: false, and with no cache path the fetch goes to the network whatever offline sets. Its skip conditions are update-notifier being off, a global npm update and CI; offline is not among them.
npm 10.2.4 sends nothing with the same steps; 10.2.5, 11.20.0 and 12.2.3 each send it. My reproducer's registry answers 404, after which pacote asks again for the full packument, so its output below shows GET /npm twice. cache: false came with #7061, in 10.2.5.
Expected Behavior
With offline set, nothing reaches the registry: no update check, or one answered from the cache only. Without offline, the update check runs as it does now.
Steps To Reproduce
-
Fetch repro.mjs at the revision I ran (
curl.exein Windows PowerShell, wherecurlisInvoke-WebRequest):curl -LO https://gist.githubusercontent.com/YevheniiKotyrlo/dd5c4d6396fab15692dd8ddd63399fc9/raw/db427f58e0f3de73e67f587037df0139f6ab8a34/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 starts a registry stand-in on 127.0.0.1 that answers 404 to every request and counts each connection and request, makes a project whose package.json has only a name and a version, and runs npm install --offline --registry=<the stand-in> there with a new cache, empty user and global config files, none of the caller's npm_config_* variables, and none of the variables the ci-info that npm loads reads to tell CI. Once npm and every process holding its output have ended, it reports what reached the stand-in. It exits 1 when anything did, 0 when nothing did, and 2 when it cannot tell, as when a step fails, npm install --offline among them.
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
# ci-info 4.4.0, which npm loads, tells CI by 60 variables; npm gets none of them
$ npm --version
12.2.3
# a stand-in registry at http://127.0.0.1:60724/ answers 404 to every request
# in <tmp>\project: a package.json with a name and a version, and no dependencies; npm's cache: <tmp>\npm-cache, new
$ npm install --offline --registry=http://127.0.0.1:60724/
up to date, audited 1 package in 4s
found 0 vulnerabilities
exit 0
# what reached the stand-in registry: 1 connection, 2 requests
connection 1: GET /npm
connection 1: GET /npm
RESULT (exit 1): defect shows (npm 12.2.3): npm install --offline exited 0, and 1 connection and 2 requests reached the registry: GET /npm, GET /npm
The latest branch at 787f1520, run from a clone, ends the same way, and so do 12.2.3 and that branch on Linux, in Docker's node:26 image. With npm 10.2.4 it ends:
RESULT (exit 0): defect does not show (npm 10.2.4): npm install --offline exited 0, and nothing reached the registry
Environment
- npm: 12.2.3
- Node.js: 26.12.1 on Windows, 26.13.1 on Linux
- OS Name: Windows 11 Pro 10.0.26300; Debian, in Docker's
node:26image - System Model Name: a desktop PC
- npm config:
; the reproducer runs npm with empty user and global config files, these through the environment, and --offline and --registry on the command line
cache = "<tmp>\npm-cache"
color = false
noproxy = "127.0.0.1"
- 主要语言
- JavaScript
- 星标
- 10.3k
- 派生
- 5k
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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可能重新可做 关联的 PR 已关闭且未合并。 未关闭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 天内回复
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurate可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 88/100
githubnext/gh-aw-workshop#6332 ·
维护者通常 1 天内回复