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.
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.
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.
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.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm