Electron Node Module Version

27 Dec 2025 in TIL

I've been building an Electron app for the first time. It was all going well until I tried to use a dependency that involved native components. When I tried to run the app, I got an error that [...] was compiled against a different Node.js version:

bash
Error occurred in handler for 'tasks:fetch': Error: The module '/private/tmp/electron-demo/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 137. This version of Node.js requires
NODE_MODULE_VERSION 140. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

It turns out that the node.js and Electron ABIs are not compatible (see the compatibility matrix), and any native code needs to be compiled specifically for Electron.

To solve the issue above, you have to rebuild native modules for Electron using @electron/rebuild:

bash
npm install --save-dev @electron/rebuild
./node_modules/.bin/electron-rebuild

Then npm start and everything works.

⚠️ You'll need to re-run electron-rebuild after every npm install.

Reproduction case

If you're looking for a simple reproduction case:

bash
git clone https://github.com/mheap/electron-build-sample
cd electron-build-sample
npm install
npm start # You'll get an error here

Rebuild the native modules and try again:

bash
./node_modules/.bin/electron-rebuild
npm start

You'll see a task that says "Do the thing".