How to fix npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! command failed in npm

npmINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 198 views

The "command failed" error with code 1 indicates a dependency failed to install, typically due to native module compilation issues. Install build tools and check Node.js version compatibility.

Quick fix

Fixes npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! command failed

# Look for errors like:
gyp ERR! find Python
gyp ERR! find VS  # Visual Studio
error: 'openssl/opensslv.h' file not found
  1. Read the actual error above
  2. Install build tools
  3. Clean and reinstall
  4. Check Node.js version
npm — error
# Look for errors like:
gyp ERR! find Python
gyp ERR! find VS # Visual Studio
error: 'openssl/opensslv.h' file not found
npm ERR! code 1
npm ERR! path /project/node_modules/package
npm ERR! command failed

What this error means

Exit code 1 is a generic failure code indicating that a command in the npm installation process failed. The error path shows which package caused the failure. This typically occurs during native module compilation (node-gyp) when build tools are missing or there's a version incompatibility. The actual error is in the output above this message—look for gyp errors, compilation failures, or missing tool messages to identify the root cause.

Typical symptoms

  • npm install fails with "command failed" and exit code 1
  • Error path points to specific package in node_modules
  • gyp ERR! messages appear in output
  • Works on some machines but fails on others
  • CI/CD pipelines fail during npm install
  • Native modules like bcrypt, sharp, or canvas fail to install

Common causes

  1. Missing build tools (Python, C++ compiler, make)
  2. Node.js version incompatible with package
  3. Native module compilation failure (node-gyp)
  4. Windows Visual Studio Build Tools not installed
  5. macOS Xcode Command Line Tools missing
  6. Corrupted node_modules or npm cache
  7. Permission issues in project directory

How to fix "npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! command failed"

1Read the actual error above

The "command failed" message is generic—find the real error:

bash
# Look for errors like:
gyp ERR! find Python
gyp ERR! find VS  # Visual Studio
error: 'openssl/opensslv.h' file not found

Scroll up in your terminal to find what actually failed.

2Install build tools

Native modules need compilation tools:

macOS:

bash
xcode-select --install

Ubuntu/Debian:

bash
sudo apt-get install build-essential python3

Windows (run as Administrator):

bash
npm install -g windows-build-tools

Alpine Linux:

bash
apk add --no-cache python3 make g++
3Clean and reinstall

Reset npm state completely:

bash
# Remove existing installation
rm -rf node_modules package-lock.json

# Clear npm cache
npm cache clean --force

# Reinstall
npm install
4Check Node.js version

Native modules compile for specific Node versions:

bash
# Check current version
node -v

# See if package specifies version requirements
npm view <package-name> engines

# Switch versions with nvm
nvm install 18
nvm use 18

# Reinstall after switching
rm -rf node_modules && npm install
5Set Python path for node-gyp

If node-gyp can't find Python:

bash
# Set Python path
npm config set python /usr/bin/python3

# On Windows, specify full path
npm config set python C:\Python39\python.exe

# Or use environment variable
export npm_config_python=/usr/bin/python3
6Fix permission issues

If you see permission denied errors:

bash
# Fix ownership of npm directories (Linux/macOS)
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules

# Or use npm with unsafe-perm
npm install --unsafe-perm
7Use alternative packages

Consider pure JavaScript alternatives:

bash
# Instead of bcrypt (native)
npm install bcryptjs

# Instead of node-sass (deprecated, native)
npm install sass

# Instead of sharp for simple operations
npm install jimp

Pure JS packages don't require compilation.

Advanced notes

Common packages that cause this error: bcrypt, sharp, canvas, sqlite3, node-sass (deprecated), serialport, and usb.

For Docker builds, always install build tools in your Dockerfile before npm install:

dockerfile
FROM node:18-slim
RUN apt-get update && apt-get install -y build-essential python3
COPY package*.json ./
RUN npm ci

On Windows, the windows-build-tools package is deprecated. Install Visual Studio Build Tools manually or use Visual Studio Community with the "Desktop development with C++" workload.

Frequently asked questions

What does "npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! c" mean?
Exit code 1 is a generic failure code indicating that a command in the npm installation process failed. The error path shows which package caused the failure. This typically occurs during native module compilation (node-gyp) when build tools are missing or there's a version incompatibility.
How do I fix "npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! c"?
The "command failed" error with code 1 indicates a dependency failed to install, typically due to native module compilation issues. Install build tools and check Node.js version compatibility.
What causes "npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! c"?
Missing build tools (Python, C++ compiler, make) Node.js version incompatible with package Native module compilation failure (node-gyp)
Is the "npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! c" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading