How to fix npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! command failed in npm
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- Read the actual error above
- Install build tools
- Clean and reinstall
- Check Node.js version
# Look for errors like:gyp ERR! find Pythongyp ERR! find VS # Visual Studioerror: 'openssl/opensslv.h' file not foundnpm ERR! code 1npm ERR! path /project/node_modules/packagenpm 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
- Missing build tools (Python, C++ compiler, make)
- Node.js version incompatible with package
- Native module compilation failure (node-gyp)
- Windows Visual Studio Build Tools not installed
- macOS Xcode Command Line Tools missing
- Corrupted node_modules or npm cache
- Permission issues in project directory
How to fix "npm ERR! code 1 npm ERR! path /project/node_modules/package npm ERR! command failed"
The "command failed" message is generic—find the real error:
# Look for errors like:
gyp ERR! find Python
gyp ERR! find VS # Visual Studio
error: 'openssl/opensslv.h' file not foundScroll up in your terminal to find what actually failed.
Native modules need compilation tools:
macOS:
xcode-select --installUbuntu/Debian:
sudo apt-get install build-essential python3Windows (run as Administrator):
npm install -g windows-build-toolsAlpine Linux:
apk add --no-cache python3 make g++Reset npm state completely:
# Remove existing installation
rm -rf node_modules package-lock.json
# Clear npm cache
npm cache clean --force
# Reinstall
npm installNative modules compile for specific Node versions:
# 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 installIf node-gyp can't find Python:
# 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/python3If you see permission denied errors:
# 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-permConsider pure JavaScript alternatives:
# Instead of bcrypt (native)
npm install bcryptjs
# Instead of node-sass (deprecated, native)
npm install sass
# Instead of sharp for simple operations
npm install jimpPure 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:
FROM node:18-slim
RUN apt-get update && apt-get install -y build-essential python3
COPY package*.json ./
RUN npm ciOn 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.