better-sqlite3: Failed to build in Electron
Can anybody help me use this in Electron?
I tried the following command,
npm install --save-dev electron-rebuild
npm install --save-dev better-sqlite3
.\node_modules\.bin\electron-rebuild.cmd
but every time I start running the application, I got an error of
..\better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 83. This version of Node.js requires
NODE_MODULE_VERSION 98. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1800)
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1170:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1800)
at Module.load (node:internal/modules/cjs/loader:982:32)
at Module._load (node:internal/modules/cjs/loader:823:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Module.require (node:internal/modules/cjs/loader:1006:19)
at require (node:internal/modules/cjs/helpers:93:18)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 17 (1 by maintainers)
@kryops experienced 100% the same as you, manually building works, but it’s tedious if
electron-rebuild
is set up as a postinstall; I have to manually rebuild after every module addition.NODE_MODULE_VERSION
is the abi number, which one can look up here: abi_version_registry eg.:Basically it means that
electron-rebuild
is rebuilding, but for the wrong version. I think it’s a wrong resolution here for new electron versions: https://github.com/electron/electron-rebuild/blob/master/src/rebuild.ts#L124 electron-rebuild uses node-abi 3.0.0, whereas node-abi is at 3.2.0, so adding the following to my package.json did the trick:Since node-abi is basically only used as a reference table, I’m fine with “overwriting” to the newest version, there are not breaking “feature” changes, it just houses the latest abi numbers for node versions.
I opened an issue at https://github.com/electron/electron-rebuild/issues/886 since it’s an issue on their end, I think we can close the issue here.
@zkldi If you’re using electron-builder, I’d recommend using a
postinstall
script to runelectron-builder install-app-deps
. It’s generally more reliable than electron-rebuild in my experience. E.g:I don’t get it, how are we supposed to fix this? I’ve added
to my
package.json
file and tried dozens of other combinations of fixes from StackOverflow and GitHub issues but no matter what I do I get:This issue is also happening to me still in 7.4.4? What did I do wrong?
This should be fixed in
v7.4.4
.@tom2strobl thanks so much for your analysis, I can confirm that the
resolutions
workaround fixes it for us as well! 😊