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 ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error