npx -y hangs on Windows when stdin is a pipe (deadlock with MCP/LSP stdio IPC)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript, nodejs
調査の方向性
まず、Windows 上で Node.js 20 または 22 を使って issue の test-npx-pipe.mjs の再現を実行し、次に stdin がパイプで渡され、-y が指定されている場合の npx プロンプトの経路を追跡します。完了条件は、@playwright/mcp プロセスが入力を待たずに起動し、説明されている piped-stdio のケースについてその動作がカバーされていることです。
索引モデルが issue の本文から書いたものです。
説明
Summary
npx -y <package> hangs indefinitely on Windows when stdin is redirected to a pipe, despite the -y flag being present. This occurs because npx still attempts to read from stdin for interactive prompts, causing a deadlock when the parent process has already taken over stdin for IPC communication.
Environment
- OS: Windows 11
- Node.js: v20.x / v22.x (tested on both)
- npm: 10.x
- Context: MCP (Model Context Protocol) stdio-based server communication
Steps to Reproduce
- Create a test script that spawns npx with piped stdio:
// test-npx-pipe.mjs
import { spawn } from 'child_process';
const proc = spawn('cmd', ['/c', 'npx', '-y', '@playwright/mcp'], {
stdio: ['pipe', 'pipe', 'pipe']
});
// Send data to stdin (simulating IPC communication)
proc.stdin.write(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: { protocolVersion: '2024-11-05', capabilities: {} }
}) + '\n');
proc.stdout.on('data', (data) => {
console.log('Received:', data.toString());
proc.kill();
});
proc.stderr.on('data', (data) => {
console.error('Error:', data.toString());
});
setTimeout(() => {
console.error('TIMEOUT: npx hung for 30 seconds');
proc.kill();
process.exit(1);
}, 30000);
- Run:
node test-npx-pipe.mjs
Expected Behavior
With the -y flag, npx should:
- Skip all interactive prompts
- Detect that stdin is not a TTY
- Immediately execute the package without waiting for user input
Actual Behavior
- npx hangs indefinitely waiting for stdin input
- The process never starts executing the target package
- No error message is shown
- The
-yflag appears to be ignored in pipe contexts
Root Cause Analysis
When stdin is a pipe (not a TTY):
- npx checks if the package needs installation/verification
- Even with
-y, npx prompts:Need to install @playwright/mcp. Ok to proceed? (y) - npx tries to read from stdin
- Deadlock: the parent process has already reserved stdin for IPC, so npx waits forever
On Unix systems, pipe EOF behavior is more explicit, allowing npx to detect non-interactive contexts. On Windows, pipe semantics differ, and -y doesn't reliably bypass prompts in this scenario.
Workaround
Direct node execution bypasses the issue:
{
"command": "C:\\Program Files\\nodejs\\node.exe",
"args": [
"C:\\Users\\<user>\\AppData\\Roaming\\npm\\node_modules\\@playwright\\mcp\\cli.js"
]
}
Impact
This affects any Windows application using stdio pipes for IPC that tries to launch npm packages via npx, including:
- MCP (Model Context Protocol) servers
- Language servers (LSP)
- Any parent-child process communication using stdin/stdout
Proposed Solutions
Option 1: Auto-detect pipe mode
Skip all prompts when stdin is not a TTY and -y is present.
Option 2: Improve -y flag reliability
Make -y unconditionally skip prompts regardless of stdin state, matching user expectations.
Option 3: Better error message
If npx detects stdin is a pipe and interaction is required, fail fast with a clear error instead of hanging:
npx: cannot prompt for input (stdin is not interactive)
Use -y to skip prompts, or install globally: npm install -g <package>
Additional Context
This issue particularly affects the MCP ecosystem where:
- All communication happens over stdio pipes (JSON-RPC protocol)
- Community documentation recommends
npx -y <package>configuration - Works fine on macOS/Linux, fails silently on Windows
- Users experience "server initialization timeout" with no clear cause
The problem is intermittent because:
- Cached packages may hit a fast path and avoid prompts
- First-time installations always trigger the hang
- Clearing npm cache (
npm cache clean --force) makes it 100% reproducible
- 主要言語
- 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 日以内に返信