How to fix npm ERR! Error: spawn node ENOENT in npm

npmBEGINNERHIGHUpdated Dec 6, 2025ยท 163 views

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.

Quick fix

Fixes ENOENT

node --version
  1. Verify Node.js is installed and accessible
  2. Install or reinstall Node.js
  3. Fix nvm or other version manager configuration
  4. Clear npm cache
npm โ€” error
node --version
npm ERR! Error: spawn node ENOENT

What this error means

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.

Typical symptoms

  • npm scripts fail immediately with 'spawn node ENOENT' error
  • npm install works but npm run commands fail
  • Scripts that worked before suddenly fail after terminal restart
  • CI/CD pipeline fails at npm script execution step
  • Error appears after switching Node versions with nvm or similar tools
  • Windows users see error when running npm from PowerShell or Git Bash
  • Docker container build fails when running npm scripts

Common causes

  1. Node.js is not installed on the system
  2. Node.js is installed but not in the system PATH
  3. nvm, fnm, or volta shell initialization not loaded in current session
  4. Corrupted Node.js installation with missing or broken symlinks
  5. npm cache corruption causing resolution failures
  6. Windows: shell not properly interpreting the command
  7. CI/CD pipeline missing setup-node action or equivalent
  8. Docker container missing Node.js installation

How to fix "npm ERR! Error: spawn node ENOENT"

1Verify Node.js is installed and accessible

First, check if Node.js is installed and available in your PATH:

bash
node --version

If 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:

bash
npm --version
which node   # On macOS/Linux
where node   # On Windows

The which or where command shows the full path to the Node.js executable.

2Install or reinstall Node.js

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:

bash
brew install node

On Ubuntu/Debian:

bash
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

On Windows with Chocolatey:

powershell
choco install nodejs

After installation, close and reopen your terminal, then verify with node --version.

3Fix nvm or other version manager configuration

If you use nvm (Node Version Manager), the most common cause is that nvm's shell initialization hasn't run:

bash
# 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 LTS

To fix permanently, ensure these lines are in your shell config file (~/.bashrc, ~/.zshrc, or ~/.profile):

bash
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:

bash
eval "$(fnm env)"

For volta users:

bash
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
4Clear npm cache

Corrupted npm cache can sometimes cause ENOENT errors:

bash
npm cache clean --force

Then delete your node_modules and reinstall:

bash
rm -rf node_modules
rm package-lock.json
npm install

This ensures a clean slate for all dependencies and their binary references.

5Check PATH environment variable

Verify that the directory containing the node executable is in your PATH:

On macOS/Linux:

bash
echo $PATH

Look for a directory containing Node.js (e.g., /usr/local/bin, /usr/bin, or ~/.nvm/versions/node/v20.x.x/bin).

On Windows:

powershell
$env:PATH -split ';'

If Node.js directory is missing, add it:

macOS/Linux (temporary):

bash
export PATH="/usr/local/bin:$PATH"

Windows (temporary in PowerShell):

powershell
$env:PATH = "C:\Program Files\nodejs;$env:PATH"

For permanent changes, edit your shell profile or use System Properties on Windows.

6Use the full path to Node (workaround)

As a temporary workaround, you can use the full path to the Node.js executable in your scripts. First, find where Node is installed:

bash
which node   # macOS/Linux
where node   # Windows

In your package.json scripts, you can use process.execPath programmatically, or reference the full path:

json
{
  "scripts": {
    "start": "/usr/local/bin/node server.js"
  }
}

Or in Node.js code, use process.execPath to get the current Node executable path:

javascript
const { spawn } = require('child_process');
spawn(process.execPath, ['script.js']);
7Fix CI/CD pipeline configuration

In CI/CD environments, ensure Node.js is properly set up before running npm commands:

GitHub Actions:

yaml
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-node@v4
    with:
      node-version: '20'
  - run: npm install
  - run: npm test

GitLab CI:

yaml
image: node:20

install:
  script:
    - npm install
    - npm test

Docker:

dockerfile
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.

Advanced notes

### 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:

bash
npm config set script-shell "C:\Program Files\Git\bin\bash.exe"

Or use cmd.exe explicitly:

bash
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:

bash
# 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.exe

If 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:

bash
npm run your-script --loglevel verbose

Or check the full error details:

bash
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:

bash
# Check for nvm
command -v nvm

# Check for fnm
command -v fnm

# Check for volta
command -v volta

# Check for n
command -v n

Stick 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:

dockerfile
# 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

Frequently asked questions

What does "ENOENT" mean?
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. json (like npm start, npm test, or lifecycle scripts), it spawns child processes using the node command.
How do I fix "ENOENT"?
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.
What causes "ENOENT"?
Node.js is not installed on the system Node.js is installed but not in the system PATH nvm, fnm, or volta shell initialization not loaded in current session
Is the "ENOENT" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading