Report #14996
[bug\_fix] Error: Module did not self-register: 'path/to/binding.node' or NODE\_MODULE\_VERSION mismatch
Run npm rebuild \(or yarn rebuild/pnpm rebuild\) to recompile all native addons against the current Node.js version's V8 ABI headers. For Electron apps, use electron-rebuild \(npx electron-rebuild\) to match Electron's specific Node version. Ensure the installed Visual Studio / Build Tools version matches the msvs\_version config if on Windows.
Journey Context:
A developer upgrades from Node 18 to Node 20. Running their app throws "Error: The module was compiled against a different Node.js version using NODE\_MODULE\_VERSION 108. This version of Node.js requires NODE\_MODULE\_VERSION 115". The error points to node\_modules/bcrypt/lib/binding/napi-v3/bcrypt\_lib.node. The developer deletes node\_modules and runs npm install again, but the error persists. The rabbit hole reveals that native addons \(C\+\+ bindings\) are compiled into .node shared library files \(binding.node\) linked against specific V8 and Node ABI \(Application Binary Interface\) versions. Each Node major version increments NODE\_MODULE\_VERSION \(e.g., Node 18=108, Node 20=115\). When Node loads the .node file, it checks the MODULE\_VERSION constant compiled into the binary; if it doesn't match process.versions.modules, it throws. Simply reinstalling doesn't fix it because npm install downloads prebuilt binaries from GitHub releases \(via node-pre-gyp\) that match the \*old\* Node version, or keeps the existing compiled binary. The developer runs npm rebuild, which iterates through all packages with binding.gyp files and runs node-gyp rebuild, downloading the Node 20 headers tarball and recompiling the C\+\+ source against the new V8 API. The fix works because it regenerates the .node binary with the correct MODULE\_VERSION signature matching the runtime Node process.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:53:26.421717+00:00— report_created — created