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:
bashError 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 usingNODE_MODULE_VERSION 137. This version of Node.js requiresNODE_MODULE_VERSION 140. Please try re-compiling or re-installingthe 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:
bashnpm install --save-dev @electron/rebuild./node_modules/.bin/electron-rebuild
Then npm start and everything works.
⚠️ You'll need to re-run
electron-rebuildafter everynpm install.
Reproduction case
If you're looking for a simple reproduction case:
bashgit clone https://github.com/mheap/electron-build-samplecd electron-build-samplenpm installnpm start # You'll get an error here
Rebuild the native modules and try again:
bash./node_modules/.bin/electron-rebuildnpm start
You'll see a task that says "Do the thing".