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.
Fixes npm ERR! The module 'package' was compiled against a different Node.js version using NODE_MODULE_VERSION
npm rebuildnpm rebuildnpm ERR! The module 'package' was compiled against a different Node.js version using NODE_MODULE_VERSION
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
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 . .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.