This content originally appeared on DEV Community and was authored by Ali nazari
“Ever encountered a cryptic ‘Module version mismatch’ error in Node.js when working with native addons like
sharp
orbcrypt
? It’s all about ABI compatibility. Let’s demystify what Node ABI versions are and why you should care.”
What is an ABI (Application Binary Interface)?
In software development, an ABI (Application Binary Interface) defines how different components of binary code interact at runtime. This includes:
- Function calling conventions
- Data types and structures
- Memory layout
- Register usage
In simpler terms, it’s the low-level handshake between a program (like Node.js) and a compiled binary module (like a C++ addon).
What is Node ABI Version?
The Node ABI version is a number assigned to a specific Node.js runtime version to indicate how native (binary) addons are expected to interface with it.
Each Node.js release introduces changes to its internal C++ APIs (via V8 or Node APIs), so the ABI version helps determine whether a native addon compiled for one version will work with another.
You can check the ABI version of your current Node.js install like this:
node -p process.versions.modules
Example output:
115
This number (115
) is the ABI version used by Node.js 20.x.
Why Does ABI Version Matter?
1.
Binary Compatibility
If you use native addons (like node-sass
, sqlite3
, bcrypt
, etc.), they are compiled against a specific ABI version. Mismatched ABI versions can lead to runtime errors.
2.
Avoiding the “Module version mismatch” Error
Example error message:
Error: The module '/app/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node'
was compiled against a different Node.js version using NODE_MODULE_VERSION 108.
This version of Node.js requires NODE_MODULE_VERSION 115.
This means the module was built for Node.js v18 (ABI 108), but you’re running Node.js v20 (ABI 115).
3.
Prebuilt Binaries
Packages often publish prebuilt binaries (e.g., sharp
, grpc
, sqlite3
). These binaries are tagged by ABI version. Tools like node-pre-gyp
use the ABI to fetch the right binary.
4.
Docker & CI/CD
When building Docker images or setting up CI pipelines, it’s critical to install or build native modules against the correct ABI for your Node.js base image.
ABI Version Table (Node.js vs ABI)
Node.js Version | ABI Version (NODE_MODULE_VERSION) |
---|---|
16.x | 93 |
18.x | 108 |
20.x | 115 |
21.x | 124 |
22.x | 131 |
Tip: You can also look this up in the Node-ABI GitHub repo or use libraries like
node-abi
.
Real-World Scenarios
Scenario 1: Docker Image Build Fails
You’re using Node.js 20, but your Docker image installs a binary module precompiled for Node 18:
Error: Module version mismatch.
Expected 115. Got 108.
Solution: Reinstall the package inside the container or use npm rebuild
.
Scenario 2: Using Prebuilt Binaries in CI
You want to cache builds of native modules across builds. Knowing the ABI version helps target the right binary per Node version:
https://example.com/bindings/sharp-v0.33.1-node-v115-linux-x64.tar.gz
Tools You Can Use
-
node-abi
: Fetch ABI versions for any Node/NW.js runtime.
npx node-abi --target 20.11.1 --runtime node
# Output: 115
process.versions.modules
: Native way to get ABI from your current Node.js.node-gyp rebuild
: Use this to recompile native modules for your current ABI.
Bonus: N-API vs Node-API vs ABI
If you’re using N-API (Node’s stable C API), you get version-agnostic compatibility:
- Modules built using N-API don’t rely on Node ABI and can work across Node versions.
- Look for
"napi"
bindings in your module.
Example folder:
node_modules/sqlite3/lib/binding/napi-v6-linux-x64
Best Practices
- Always rebuild native modules after upgrading Node.js:
npm rebuild
In Docker, prefer building native modules during the image build, not before.
Use packages that support N-API when available for long-term compatibility.
Cache your binaries per ABI version in CI/CD environments.
Conclusion
The Node ABI version is a critical piece of the puzzle when dealing with native Node.js modules.
Whether you’re debugging module mismatch errors or building cross-version compatible apps, understanding ABI versions helps you work smarter and avoid runtime surprises.
Have you ever hit a mysterious error due to ABI mismatch? Share your experience in the comments!
This content originally appeared on DEV Community and was authored by Ali nazari