You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Expose --prefer-direct-exec for npm run and add a production note (tracking; blocked by @npmcli/run-script https://github.com/npm/run-script/issues/237) #8509
There is no CLI/config switch to make npm run wait for the actual app process (e.g., node) rather than /bin/sh. In containerized environments (Docker/Kubernetes), this can cause npm to exit when the shell exits on SIGTERM, stopping the container before the Node.js app completes its graceful shutdown (e.g., server.close() / cleanup). Documentation also does not clearly highlight this operational footgun or provide an official opt-in workaround at the CLI level.
Expected Behavior
Provide an opt-in in npm/cli to surface a switch that makes npm run wait for the real target process:
CLI flag: npm run --prefer-direct-exec
Config (.npmrc): prefer-direct-exec=true
(Optional) Env: NPM_PREFER_DIRECT_EXEC=1
When enabled (Unix):
Either directly spawn simple single-command scripts without a shell, or
Exec-replace the shell so npm’s direct child is the target process.
Default behavior remains unchanged for compatibility. Also, add a short “Production note” in the run-script docs explaining this flag and recommending exec or direct exec in containerized environments.
Steps To Reproduce
In a Linux containerized environment (e.g., node:18-slim) with PID 1 = dumb-init or tini, orchestrated by Kubernetes.
With package.json using "start": "node index.js" (no exec).
Run the pod and terminate it via kubectl delete pod (sends SIGTERM).
Observe: The shell (ash/dash) can exit promptly on SIGTERM; npm exits because its direct child is gone; the container stops before the Node app finishes graceful shutdown.
Workaround today: Change the script to "start": "exec node index.js" so the shell exec-replaces into node. There is no CLI flag to achieve this behavior without editing package.json.
Note: This CLI request is blocked by the implementation proposal in @npmcli/run-script: npm/run-script#237
Environment
npm: 10.x
Node.js: 18.x (or 20.x)
OS Name: Linux container
System Model Name: Kubernetes (SIGTERM on pod termination; PID1 = dumb-init or tini)
@seungwanHam Thanks for taking the time to share your idea! New ideas are always appreciated and are better suited for our RFC repo instead since that's the right place in order to get more attention from the rest of the team and the community.
Activity
milaninfy commentedon Aug 15, 2025
@seungwanHam Thanks for taking the time to share your idea! New ideas are always appreciated and are better suited for our RFC repo instead since that's the right place in order to get more attention from the rest of the team and the community.