[BUG] npx -y takes 70 s offline before running a cached package (about 5 min when packets are dropped)

オープン
#10,320 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@evilive3000 がすでに取り組んでいます。

2026年11月20日 から。

  • #10322 @evilive3000 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
67/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js
領域
backend, cli

調査の方向性

Start with workspaces/libnpmexec/lib/index.js and inspect the getManifest call that uses preferOnline: true; compare its behavior with --prefer-offline and the reported cache fallback. Reproduce with a cached package and an unreachable registry, then check that npx starts it promptly while preserving normal online behavior. The issue gives timings and reproduction steps but does not name a test file.

索引モデルが issue の本文から書いたものです。

説明

Triage Requested
Is there an existing issue for this?
  • I have searched the existing issues. #7295 is related: npx re-checks the registry on every run. This issue is about how long that check takes when the registry can't be reached.
This issue exists in the latest npm version
  • I measured on npm 11.2.0. On npm 12.2.3, workspaces/libnpmexec/lib/index.js still fetches the manifest with preferOnline: true (line 30).
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

npx -y <package> always fetches the package's manifest from the registry, even when the package is already in the npx cache: getManifest in libnpmexec passes preferOnline: true. When the registry can't be reached, npm's fetch retries run first, and only then does npx fall back to the cached copy and start the package. That takes 70 s. When packets are dropped (a captive portal or a firewall), it takes about 5 minutes.

This matters for MCP servers in particular. Most MCP client configurations start their servers with npx -y <server>, so offline every agent start waits over a minute for each server, and clients with shorter startup timeouts give up first.

Measured with @modelcontextprotocol/server-memory, already in the npx cache: the time from starting it until it answers the MCP initialize request over stdio. To make the registry unreachable without changing any configuration, I set npm_config_https_proxy for the command only.

Registry unreachable (5 alternating rounds) Median Range
npx -y 70,408 ms 70,382–70,478
npm_config_fetch_retries=0 npx -y 433 ms 372–567
npx -y --prefer-offline 379 ms 351–400
Other failures (one run each) npx -y --prefer-offline
DNS fails (proxy proxy.invalid) 70.4 s 0.38 s
Connection refused (proxy 127.0.0.1:9) 70.7 s 0.55 s
Packets dropped (proxy 10.255.255.1:8080) 295.5 s 0.34 s

With the registry set to registry.invalid (no proxy), it fails after 70.2 s, so a DNS failure gets the same retries. That run fails only because nothing is cached under that URL.

Expected Behavior

When the package is in the cache and the registry can't be reached, npx runs the cached version quickly. For example, it could skip retries for DNS failures and refused connections during this freshness check, or give the check a short timeout.

Steps To Reproduce
  1. Online, run an MCP server once so it's cached: npx -y @modelcontextprotocol/server-memory.
  2. Make the registry unreachable, for example with npm_config_https_proxy=http://proxy.invalid:8080 for that command, or by disconnecting from the network.
  3. Start it again with npx -y @modelcontextprotocol/server-memory and send an initialize request on stdin. The reply arrives after about 70 s.
  4. Repeat with --prefer-offline or npm_config_fetch_retries=0: the reply arrives in about 0.4 s.
Environment
  • npm: 11.2.0 (the same preferOnline: true in 12.2.3)
  • Node.js: 22.14.0
  • OS Name: macOS 14.2.1 (Apple silicon)
  • System Model Name: Apple silicon Mac
  • npm config: defaults

Measured with wits. I used an AI assistant to help investigate and write this up; the numbers are from the runs described above.

主要言語
JavaScript
スター
10.3k
フォーク
5k
平均マージ
4日 11時間
マージ済み PR(30日)
26

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npm/cli のほかの issue

npm/cli の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。