The ESRCH error occurs when npm or Node.js attempts to interact with a process that doesn't exist or has already terminated. This typically happens during process cleanup, DNS lookups, or when tools try to kill child processes that have already exited.
ESRCH is a Unix error code meaning 'Error — Search' (errno 3), thrown when a system call targets a non-existent process. In npm and Node.js, this error manifests in two main scenarios: (1) when Node.js tries to terminate a child process that has already exited or never started properly, creating a race condition, and (2) when npm fails to perform DNS lookups during network operations like package installation or registry communication. This error is particularly common in development tools like Puppeteer, process managers (PM2), terminal multiplexers, and debugging scenarios. The root cause is typically a mismatch between what the application thinks is running and the actual process state on the system.
First, verify whether the problem is a genuine missing process or a race condition. Try running the command with verbose logging:
npm install -verboseOr for npm start/scripts:
npm run start -- --verboseIf the error occurs intermittently, it's likely a race condition. If it's consistent, continue to the next steps.
Start with a clean slate by removing cached data and dependencies:
# Clean npm cache
npm cache clean --force
# Remove node_modules and lock file
rm -rf node_modules package-lock.json
# Reinstall dependencies
npm installThis resolves issues where npm has stale process tracking information or corrupted metadata.
If the error mentions 'syscall: getaddrinfo', the issue is network-related:
For Vagrant/VM users:
# Reload your Vagrant box to reset network
vagrant reload
# Test connectivity
ping google.com
curl -I https://registry.npmjs.orgFor Docker/container users:
Ensure DNS is configured in your container:
# Check DNS resolver
cat /etc/resolv.conf
# If using Docker, add --dns flag
docker run --dns 8.8.8.8 your-imageFor WSL (Windows Subsystem for Linux):
Update your /etc/wsl.conf to set DNS:
[network]
generateResolvConf = true
nameserver 8.8.8.8Then restart WSL: wsl --shutdown
If the error mentions 'syscall: kill', add error handling in your code to gracefully handle missing processes:
// Wrap process.kill() with error handling
function safeKill(pid, signal = 'SIGTERM') {
try {
process.kill(pid, signal);
} catch (error) {
if (error.code !== 'ESRCH') {
throw error; // Re-throw if it's not "process not found"
}
// Silently ignore ESRCH - process already terminated
}
}For npm scripts in package.json:
Add error handling to your start/stop scripts:
{
"scripts": {
"start": "node app.js || true",
"stop": "pkill -f 'node app.js' || true"
}
}The || true prevents the script from failing if the process doesn't exist.
If behind a corporate proxy or firewall, configure npm to use your proxy:
# Configure npm to use your proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# For authenticated proxies
npm config set proxy http://username:[email protected]:8080
# Test registry connectivity
npm ping
# View current configuration
npm config listIf you don't know your proxy settings, contact your IT department or check your browser's proxy settings.
ESRCH errors in specific tools require targeted fixes: For Puppeteer/Playwright, ensure all shared libraries are installed (ldd $(which node) to check) and use headless flags appropriate to your OS. In PM2 or process managers, enable detailed logging with pm2 logs to catch the actual process startup failure before ESRCH is thrown. On Windows with PTY (pseudo-terminal) environments, the discrepancy between stored and actual PIDs is a known issue—upgrading to the latest Node.js LTS usually resolves this. For CI/CD pipelines (GitHub Actions, GitLab CI), ensure runners have sufficient resources and consider using npm ci instead of npm install for reproducible installs.
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 ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error