npx -y hangs on Windows when stdin is a pipe (deadlock with MCP/LSP stdio IPC)
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 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 小时
- 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 天内回复