The npm SIGINT error occurs when a process is interrupted by pressing Ctrl+C or receiving an interrupt signal. This is usually expected behavior but can leave npm operations in an inconsistent state if interrupted at the wrong time.
The npm SIGINT error occurs when a process is terminated by a SIGINT (interrupt) signal, typically when you press Ctrl+C in your terminal. This is a standard Unix signal mechanism for gracefully terminating processes. When you interrupt an npm command (like npm install, npm start, or npm run), npm catches the SIGINT signal and reports it as an error. In most cases, this error is not fatal and simply means the process was stopped mid-execution. However, it's important to understand what caused the interruption and whether your environment was left in a corrupted state, especially if SIGINT was received during npm install. The error message itself doesn't indicate a problem with your code—it's npm's way of acknowledging that a running process was interrupted by a signal rather than completing normally.
First, confirm whether you intentionally pressed Ctrl+C or if the process was interrupted by something else:
# If you just pressed Ctrl+C, the error is expected
# Simply try running the command again
npm install
# Check if a process manager is killing npm
ps aux | grep npmIf you deliberately stopped an npm command, this is expected behavior and the error can be safely ignored.
If you interrupted npm install mid-execution, your node_modules may be in an inconsistent state:
# Remove corrupted dependencies and lock file
rm -rf node_modules package-lock.json
# Reinstall all dependencies
npm installFor yarn users:
rm -rf node_modules yarn.lock
yarn installnpm doesn't always properly handle signals like SIGINT. Run Node directly for better signal handling:
# Instead of: npm start
# Run directly without npm:
node server.js
# For development with auto-reload:
npx nodemon server.jsThis gives your process direct control over signal handling.
Add signal handlers to manage SIGINT gracefully:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200);
res.end('Hello World\n');
});
function gracefulShutdown() {
console.log('Received SIGINT, shutting down gracefully...');
server.close(() => {
console.log('Server closed. Exiting.');
process.exit(0);
});
// Force shutdown after 5 seconds if graceful shutdown fails
setTimeout(() => {
console.error('Could not close connections in time');
process.exit(1);
}, 5000);
}
process.on('SIGINT', gracefulShutdown);
process.on('SIGTERM', gracefulShutdown);
server.listen(3000);When running via npm, SIGINT can sometimes trigger twice. Use process.once() instead:
// Instead of process.on() which allows multiple calls
process.once('SIGINT', () => {
console.log('SIGINT received once, shutting down');
// Cleanup code here
process.exit(0);
});This prevents your handler from executing multiple times on rapid interrupts.
In Docker and CI/CD systems, SIGINT errors are often due to container termination:
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
# Run node directly (not through npm) to handle signals properly
CMD ["node", "server.js"]For GitHub Actions, ensure long-running processes have proper timeouts:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm run buildSignal Types: SIGINT is sent when Ctrl+C is pressed (exit code 130), while SIGTERM is a more graceful termination signal used by process managers and container orchestration systems. SIGKILL (exit code 137) is forceful and cannot be caught by applications.
npm Architecture Issue: npm acts as a parent process to your Node.js script, which can interfere with signal propagation. Some npm versions (9.6.7 to 9.8.1) had regressions in signal handling. Running Node directly bypasses this problem entirely.
Multiple SIGINT Calls: If your SIGINT handler is called multiple times, check if the server is still listening before attempting cleanup: if (server.listening) { server.close(...) }
Lock File Corruption: If npm install was severely interrupted, you might also need to clear the npm cache: npm cache clean --force before reinstalling.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"