How to fix npm ERR! The module 'package' was compiled against a different Node.js version using NODE_MODULE_VERSION in npm
This error occurs when a native module's compiled binary doesn't match your current Node.js version. The NODE_MODULE_VERSION ABI changed, requiring recompilation.
Quick fix
Fixes npm ERR! The module 'package' was compiled against a different Node.js version using NODE_MODULE_VERSION
npm rebuild- Rebuild native modules
- Clean reinstall (most reliable)
- Verify Node.js version consistency
- Rebuild specific package
npm rebuildnpm ERR! The module 'package' was compiled against a different Node.js version using NODE_MODULE_VERSION
What this error means
This error means a native module (C++ addon) was compiled for a different Node.js version than you're currently running. Native modules are compiled to a specific ABI (Application Binary Interface) version, identified by NODE_MODULE_VERSION. Each Node.js major version has a different ABI: - Node.js 16.x = ABI 93 - Node.js 18.x = ABI 108 - Node.js 20.x = ABI 115 - Node.js 22.x = ABI 127 When these don't match, the module can't load. This commonly happens when: - You upgraded Node.js but didn't reinstall node_modules - You copied node_modules from another machine - Different Node.js versions in development vs production
Typical symptoms
- Error mentions NODE_MODULE_VERSION mismatch
- Application crashes on startup with native module errors
- Module works on one machine but not another
- Error after upgrading Node.js
Common causes
- Node.js was upgraded without rebuilding native modules
- node_modules copied from different Node.js environment
- Docker image uses different Node.js than development
- CI/CD uses different Node.js version than local
- Multiple Node.js versions installed, wrong one used
How to fix "npm ERR! The module 'package' was compiled against a different Node.js version using NODE_MODULE_VERSION"
The quickest fix is to rebuild all native modules:
npm rebuildThis recompiles all native modules for your current Node.js version.
For a completely fresh build:
rm -rf node_modules package-lock.json
npm installThis removes all cached binaries and reinstalls everything.
Ensure you're using the same Node.js everywhere:
# Check current version
node --version
# Check which node is being used
which node
# If using nvm, verify active version
nvm currentAlso check that your IDE/editor is using the same Node.js version as your terminal.
If you know which package is problematic:
npm rebuild bcrypt
# or
npm rebuild sqlite3Don't copy node_modules into Docker. Add to .dockerignore:
node_modulesLet Docker install fresh:
FROM node:20
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .Advanced notes
Common affected packages: bcrypt, sqlite3, canvas, sharp, node-sass, leveldown—any package with C++ native code.
Prevention:
- Use .nvmrc to lock Node.js version
- Never copy node_modules between environments
- Run npm rebuild after Node.js upgrades
- Use same Node.js version in CI/CD as development
ABI version lookup: Check which ABI your Node.js uses:
node -p "process.versions.modules"package-lock.json: The lock file may reference wrong platform binaries. Deleting it ensures fresh resolution for your platform.
Frequently asked questions
- What does "npm ERR! The module 'package' was compiled against a different Node.js" mean?
- js version than you're currently running. Native modules are compiled to a specific ABI (Application Binary Interface) version, identified by NODE_MODULE_VERSION. x = ABI 127 When these don't match, the module can't load.
- How do I fix "npm ERR! The module 'package' was compiled against a different Node.js"?
- This error occurs when a native module's compiled binary doesn't match your current Node.js version. The NODE_MODULE_VERSION ABI changed, requiring recompilation.
- What causes "npm ERR! The module 'package' was compiled against a different Node.js"?
- Node.js was upgraded without rebuilding native modules node_modules copied from different Node.js environment Docker image uses different Node.js than development
- Is the "npm ERR! The module 'package' was compiled against a different Node.js" 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
- 📖Node.js: C++ Addons(Official Docs)
- 🐙GitHub: node-gyp repository(GitHub)
- 💬Stack Overflow: npm native modules(Stack Overflow)