npx -y hangs on Windows when stdin is a pipe (deadlock with MCP/LSP stdio IPC)
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, nodejs
Direzione di ricerca
Inizia eseguendo su Windows la riproduzione test-npx-pipe.mjs dell'issue con Node.js 20 o 22, quindi traccia il percorso del prompt di npx quando stdin è rediretto e -y è presente. Il lavoro è completato quando il processo @playwright/mcp si avvia senza attendere input e il comportamento è coperto per il caso piped-stdio descritto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- JavaScript
- Stelle
- 10.3k
- Fork
- 5k
- Merge medio
- 4g 11h
- PR unite (30g)
- 26
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsForse già presa @saruk-vedant l’ha presa 7 giorni fa. ApertaBug Needs Triage Triage Requested
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyForse già presa @drawliin l’ha presa 42 giorni fa. Apertacmd:delete Priority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 2 giorni
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaEngineering Priority 1
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysForse già presa @greenlincoln05 l’ha presa 63 giorni fa. ApertaPriority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
possible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Mintplex-Labs/anything-llm#7388 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
v6: Minified bootstrap.min.css is missing header infoForse già presa @lazerg l’ha presa oggi. Apertabug build confirmed has-pr v6
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
githubnext/gh-aw-workshop#6332 ·
I maintainer di solito rispondono entro 1 giorno