How to fix npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stack Error: Failed to execute in npm
This error occurs when node-pre-gyp can't find prebuilt binaries and fails to compile from source. Usually caused by missing build tools or unsupported platform.
Quick fix
Fixes npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stack Error: Failed to execute
sudo apt-get update
sudo apt-get install -y build-essential python3- Install build tools
- Use supported Node.js version
- Clean and retry
- Check for platform-specific issues
sudo apt-get updatesudo apt-get install -y build-essential python3npm ERR! node-pre-gyp ERR! build errornpm ERR! node-pre-gyp ERR! stack Error: Failed to execute
What this error means
node-pre-gyp is a tool that downloads prebuilt native module binaries. When it can't find a prebuilt binary for your platform/Node.js combination, it falls back to compiling from source using node-gyp. The "build error" means this fallback compilation failed. This is usually because: - Build tools (compiler, make, Python) aren't installed - The package doesn't support your platform - There's a version incompatibility node-pre-gyp is commonly used by packages like bcrypt, sqlite3, and grpc.
Typical symptoms
- Error shows 'node-pre-gyp ERR! build error'
- Stack trace mentions 'Failed to execute'
- Happens with packages like bcrypt, sqlite3, grpc
- Install works on some machines but fails on others
Common causes
- Build tools not installed (gcc, g++, make, Python)
- No prebuilt binary for your platform/Node.js version
- Windows SDK missing on Windows
- Xcode Command Line Tools missing on macOS
- Permission issues during compilation
How to fix "npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stack Error: Failed to execute"
node-pre-gyp needs build tools for fallback compilation:
Linux (Debian/Ubuntu):
sudo apt-get update
sudo apt-get install -y build-essential python3macOS:
xcode-select --installWindows (run as Administrator):
npm install --global --production windows-build-toolsPrebuilt binaries are usually available for LTS versions:
# Switch to LTS
nvm install --lts
nvm use --lts
# Clean install
rm -rf node_modules package-lock.json
npm installClear any corrupted state:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installSome platforms need extra setup:
Alpine Linux:
apk add --no-cache python3 make g++Windows - if Windows SDK errors:
Install Visual Studio with "Desktop development with C++" workload.
Permission issues:
npm install --unsafe-permIf compilation keeps failing, use pure JS alternatives:
| Native Package | JS Alternative |
|---------------|----------------|
| bcrypt | bcryptjs |
| sqlite3 | better-sqlite3, sql.js |
| node-sass | sass |
Advanced notes
Deprecated package warning: The original node-pre-gyp package is deprecated. The maintained version is @mapbox/node-pre-gyp. If you're a package author, migrate to the maintained version.
Verbose output: Get more details about what's failing:
npm install --verboseBuild from source explicitly:
npm install --build-from-sourceDocker optimization: In multi-stage builds, compile in a full image:
FROM node:20 AS builder
RUN apt-get update && apt-get install -y build-essential python3
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:20-slim
COPY --from=builder /app/node_modules ./node_modulesCI/CD caching: Cache node_modules in CI to avoid rebuilding native modules on every run.
Frequently asked questions
- What does "npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stac" mean?
- node-pre-gyp is a tool that downloads prebuilt native module binaries. js combination, it falls back to compiling from source using node-gyp. The "build error" means this fallback compilation failed.
- How do I fix "npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stac"?
- This error occurs when node-pre-gyp can't find prebuilt binaries and fails to compile from source. Usually caused by missing build tools or unsupported platform.
- What causes "npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stac"?
- Build tools not installed (gcc, g++, make, Python) No prebuilt binary for your platform/Node.js version Windows SDK missing on Windows
- Is the "npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stac" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐GitHub: node-pre-gyp(Official Docs)
- ๐ฌStack Overflow: node-pre-gyp(Stack Overflow)
- ๐npm docs: permissions errors(Official Docs)