How to fix npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: Command failed in npm
The 'gyp ERR! configure error' occurs when npm fails to compile native Node.js modules due to missing system dependencies, build tools, or Python. This happens during npm install when a package requires compilation.
Quick fix
Fixes gyp ERR!
npm cache clean --force
rm -rf node_modules package-lock.json- Clear npm cache and node_modules
- Update Node.js to a stable LTS version
- Install platform-specific build tools
- Verify Python is installed and in PATH
npm cache clean --forcerm -rf node_modules package-lock.jsonnpm ERR! gyp ERR! configure errornpm ERR! gyp ERR! stack Error: Command failed
What this error means
Node-gyp is a tool that compiles native C/C++ modules for Node.js packages. When you run npm install, gyp attempts to configure and build these native modules using your system's C++ compiler and Python. The 'configure error' means gyp failed to validate or set up your build environment—typically because required build tools, compilers, or Python are missing.
Typical symptoms
- npm install hangs or fails with 'gyp ERR! configure error'
- Error mentions 'command failed' or 'not found' for cl.exe, gcc, python, or make
- CI/CD pipelines fail during npm install
- Works on one machine but fails on another
- Error appears after upgrading Node.js or npm version
Common causes
- Missing or incompatible Python (gyp requires Python 2.7+ or Python 3)
- Visual Studio Build Tools not installed (Windows requirement)
- Missing C/C++ compiler or build tools (gcc, clang, make on macOS/Linux)
- Xcode Command Line Tools not installed (macOS requirement)
- build-essential package not installed (Linux requirement)
- Node.js or npm version mismatch
How to fix "npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: Command failed"
Start with a clean slate:
npm cache clean --force
rm -rf node_modules package-lock.jsonEnsure you're using a stable version:
node --versionUpgrade to the latest LTS from https://nodejs.org or use nvm:
nvm install --lts
nvm use --ltsWindows (PowerShell as Administrator):
npm install --global --production windows-build-toolsAlternatively, install Visual Studio Build Tools with 'Desktop development with C++' workload.
macOS:
xcode-select --installLinux (Ubuntu/Debian):
sudo apt-get update
sudo apt-get install build-essential python3Check Python is accessible:
python3 --version
which python3Configure npm to use Python:
npm config set python python3Ensure you have the latest node-gyp:
npm install --global node-gyp@latestOnce build tools are installed:
npm installAdvanced notes
On Docker/containers, base images often lack build tools—add them in your Dockerfile: RUN apt-get install -y build-essential python3. In CI/CD environments, ensure your runner has access to compilers. Some organizations use pre-built binary caches to avoid recompilation entirely. Windows-build-tools installation requires ~3GB disk space and Administrator privileges.
Frequently asked questions
- What does "gyp ERR!" mean?
- js packages. When you run npm install, gyp attempts to configure and build these native modules using your system's C++ compiler and Python. The 'configure error' means gyp failed to validate or set up your build environment—typically because required build tools, compilers, or Python are missing.
- How do I fix "gyp ERR!"?
- The 'gyp ERR! configure error' occurs when npm fails to compile native Node.js modules due to missing system dependencies, build tools, or Python. This happens during npm install when a package requires compilation.
- What causes "gyp ERR!"?
- Missing or incompatible Python (gyp requires Python 2.7+ or Python 3) Visual Studio Build Tools not installed (Windows requirement) Missing C/C++ compiler or build tools (gcc, clang, make on macOS/Linux)
- Is the "gyp ERR!" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 📖node-gyp GitHub Repository(Official Docs)
- 📖node-gyp Prerequisites(Official Docs)
- 💬Stack Overflow: node-gyp Configuration(Stack Overflow)