[BUG] `npm install --offline` still sends requests to the registry: the update check asks it for npm

Đang mở
#10,371 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@charan-rathore đang làm issue này rồi.

Từ ngày 27/11/2026.

  • #10374 của @charan-rathore — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, nodejs
Lĩnh vực
cli, devtools

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Needs Triage
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
  1. Fetch repro.mjs at the revision I ran (curl.exe in Windows PowerShell, where curl is Invoke-WebRequest):

    curl -LO https://gist.githubusercontent.com/YevheniiKotyrlo/dd5c4d6396fab15692dd8ddd63399fc9/raw/db427f58e0f3de73e67f587037df0139f6ab8a34/repro.mjs
    
  2. Run it with a Node that npm 12 runs on:

    node repro.mjs
    

    With 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, and node 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:26 image
  • 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"
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của npm/cli

Tất cả issue của npm/cli

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.