This error occurs when npm cannot locate the Node.js executable in your system PATH. Common causes include Node.js not being installed, PATH misconfiguration, or nvm environment issues.
The "spawn node ENOENT" error in npm indicates that the operating system cannot find the `node` executable when npm tries to spawn a child process. ENOENT stands for "Error NO ENTry" - a Unix/POSIX error code meaning a file or directory does not exist. When npm runs scripts defined in your package.json (like `npm start`, `npm test`, or lifecycle scripts), it spawns child processes using the `node` command. If `node` is not in your system's PATH environment variable, or if the PATH is not correctly configured in the current shell session, the operating system cannot locate the executable. This error is especially common when using Node version managers like nvm, fnm, or volta, where the Node.js installation is not in the standard system location. It can also occur in Docker containers where Node.js wasn't properly installed, in CI/CD pipelines with missing setup steps, or on Windows with WSL where environment variables may not be properly inherited.
First, check if Node.js is installed and available in your PATH:
node --versionIf this returns a version number (e.g., v20.10.0), Node.js is accessible. If you get "command not found" or similar, Node.js is either not installed or not in your PATH.
Also verify npm itself:
npm --version
which node # On macOS/Linux
where node # On WindowsThe which or where command shows the full path to the Node.js executable.
If Node.js is not installed, install it from the official website or using a package manager:
Using the official installer:
Download from https://nodejs.org/ and run the installer.
On macOS with Homebrew:
brew install nodeOn Ubuntu/Debian:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejsOn Windows with Chocolatey:
choco install nodejsAfter installation, close and reopen your terminal, then verify with node --version.
If you use nvm (Node Version Manager), the most common cause is that nvm's shell initialization hasn't run:
# Load nvm in current session
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Then set the Node version
nvm use node # Use latest installed
nvm use 20 # Use specific version
nvm use --lts # Use latest LTSTo fix permanently, ensure these lines are in your shell config file (~/.bashrc, ~/.zshrc, or ~/.profile):
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"For fnm users:
eval "$(fnm env)"For volta users:
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"Corrupted npm cache can sometimes cause ENOENT errors:
npm cache clean --forceThen delete your node_modules and reinstall:
rm -rf node_modules
rm package-lock.json
npm installThis ensures a clean slate for all dependencies and their binary references.
Verify that the directory containing the node executable is in your PATH:
On macOS/Linux:
echo $PATHLook for a directory containing Node.js (e.g., /usr/local/bin, /usr/bin, or ~/.nvm/versions/node/v20.x.x/bin).
On Windows:
$env:PATH -split ';'If Node.js directory is missing, add it:
macOS/Linux (temporary):
export PATH="/usr/local/bin:$PATH"Windows (temporary in PowerShell):
$env:PATH = "C:\Program Files\nodejs;$env:PATH"For permanent changes, edit your shell profile or use System Properties on Windows.
As a temporary workaround, you can use the full path to the Node.js executable in your scripts. First, find where Node is installed:
which node # macOS/Linux
where node # WindowsIn your package.json scripts, you can use process.execPath programmatically, or reference the full path:
{
"scripts": {
"start": "/usr/local/bin/node server.js"
}
}Or in Node.js code, use process.execPath to get the current Node executable path:
const { spawn } = require('child_process');
spawn(process.execPath, ['script.js']);In CI/CD environments, ensure Node.js is properly set up before running npm commands:
GitHub Actions:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
- run: npm testGitLab CI:
image: node:20
install:
script:
- npm install
- npm testDocker:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]Ensure the Node.js version in your CI matches your development environment.
### Platform-Specific Considerations
Windows:
On Windows, npm scripts may fail if the shell doesn't properly interpret the command. Try setting the script-shell config:
npm config set script-shell "C:\Program Files\Git\bin\bash.exe"Or use cmd.exe explicitly:
npm config set script-shell "C:\Windows\System32\cmd.exe"WSL (Windows Subsystem for Linux):
If you're running npm in WSL but have Windows Node installed, there can be PATH conflicts. Ensure you're using the Linux Node installation:
# Check which node is being used
which node
# Should show a Linux path like /usr/bin/node or ~/.nvm/...
# NOT /mnt/c/Program Files/nodejs/node.exeIf it shows a Windows path, install Node.js properly in WSL or adjust your PATH to prioritize Linux binaries.
### Debugging ENOENT Errors
To get more information about which file is missing, run npm with verbose logging:
npm run your-script --loglevel verboseOr check the full error details:
npm run your-script 2>&1 | head -50### Node Version Manager Conflicts
If you have multiple version managers installed (nvm, fnm, volta, n), they can conflict. Check for multiple installations:
# Check for nvm
command -v nvm
# Check for fnm
command -v fnm
# Check for volta
command -v volta
# Check for n
command -v nStick with one version manager and ensure only that one is initialized in your shell profile.
### Docker Multi-Stage Builds
In Docker multi-stage builds, make sure Node.js is available in each stage that needs it:
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage - also needs Node!
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY package*.json ./
RUN npm ci --only=production
CMD ["node", "dist/index.js"]### Common Related Errors
- spawn ENOENT (without "node") - Similar issue but for other executables
- ENOENT: no such file or directory - Missing file in your project
- Error: Cannot find module - Missing Node module, different from ENOENT
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
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 EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error