better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

Electron app crashing with latest better-sqlite3

Open jayakrishnankp opened this issue 1 year ago • 8 comments

I was using better-sqlite3 with the version as ^8.3.0 in package.json in my electron app for some time. On a recent npm install, better-sqlite3 version 8.6.0 was installed, which causes my app to crash with an error message:

node_modules/better-sqlite3/build/Release/better_sqlite3.node' was compiled against a 
different Node.js version using NODE_MODULE_VERSION 108. This version of Node.js 
requires NODE_MODULE_VERSION 116.

NOTE: When I switch my version back to 8.4.0 or less, everything works fine

Steps to Reproduce

  1. Create a sample Electron app (you can clone the quick start project here) or use any existing one
  2. Install better-sqlite3 version 8.6.0 and electron-rebuild
  3. Import better-sqlite3 in main.js and initialize the db:
    const sqlite = require("better-sqlite3");
    const db = sqlite("newdb.sqlite.db")
    console.log("Created db", db); 
    
  4. Run the electron app using npm run start
  5. See error

Versions

  • Node: 18.12.1
  • Electron: 24.1.2
  • electron-rebuild: 3.3.0

Expected behaviour No error and the console log is expected

Addition Context

  • After using electron-rebuild to rebuild the package (which is the usual case), the process exits without any better-sqlite3 error message: The crash happens at the bit of code which creates the new db file:
const db = require('better-sqlite3')('myDb.db');
  • And the error message is:
node_modules/electron/dist/Electron.app/Contents/MacOS/Electron exited with signal SIGKILL

jayakrishnankp avatar Sep 11 '23 12:09 jayakrishnankp

Did you clean up the node_modules folder? Node Module Version 116 belongs to Electron 25 / 26, not 24.

Due to a shortcoming in how prebuild handles the node module version when resolving package names, this current leads to issues when using Electron 26 with the prebuilt binaries https://github.com/WiseLibs/better-sqlite3/issues/1044#issuecomment-1709549849.

neoxpert avatar Sep 11 '23 13:09 neoxpert

Did you clean up the node_modules folder? Node Module Version 116 belongs to Electron 25 / 26, not 24.

Yes. I always remove the node_modules and package-lock before doing npm install.

Due to a shortcoming in how prebuild handles the node module version when resolving package names, this current leads to issues when using Electron 26 with the prebuilt binaries #1044 (comment).

I am not sure if the same happens for older versions as well. I am using Electron 24.1.2 and I couldn't find any issues which mention the error for this version in Electron repo. I am also not using prebuilt binaries in my case. Just using electron-rebuild to rebuild better-sqlite3, then packaging it using electron-forge.

jayakrishnankp avatar Sep 15 '23 13:09 jayakrishnankp

Well if you still get the error

node_modules/better-sqlite3/build/Release/better_sqlite3.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 108. This version of Node.js requires NODE_MODULE_VERSION 116.

something on your machine did either resolve the wrong prebuilt binary or you are really executing with Electron 25 / 26. I just downgraded a project to Electron 24.1.2 for testing purposes and had no issues when installing [email protected] aswell as on a fresh project. As I am using electron-builder for the native module part, I tend to suspect electron-rebuild maybe not doing what it should.

neoxpert avatar Sep 15 '23 16:09 neoxpert

something on your machine did either resolve the wrong prebuilt binary or you are really executing with Electron 25 / 26. I just downgraded a project to Electron 24.1.2 for testing purposes and had no issues when installing [email protected] aswell as on a fresh project. As I am using electron-builder for the native module part, I tend to suspect electron-rebuild maybe not doing what it should.

Ohhk. Thank you so much for testing it yourself @neoxpert. I'll try the same with electron-builder (hoping it won't require big changes) and see if it's an issue with electron-rebuild.

jayakrishnankp avatar Sep 18 '23 05:09 jayakrishnankp

I lowered it to 25.8.1 with no problem, but I couldn't upgrade to 26.x

tetap avatar Sep 21 '23 03:09 tetap

I lowered it to 25.8.1 with no problem, but I couldn't upgrade to 26.x

Saved my life

TylerTemp avatar Oct 15 '23 04:10 TylerTemp

I lowered it to 25.8.1 with no problem, but I couldn't upgrade to 26.x

Saved my life

It is now available to support 26.x 27.x requires 9.0.0

tetap avatar Oct 15 '23 04:10 tetap

I was having a similar issue to @jayakrishnankp , and fixed it by updating my mac to a newer version of OSX.

In my case, the root cause of:

After using electron-rebuild to rebuild the package (which is the usual case), the process exits without any better-sqlite3 error message

was due to a darwin binary being loaded that is not compatible with my current operating system.

I bisected versions down to v8.5.2, which added darwin-arm64 prebuilds. Unfortunately, it seems that prebuild-install does not take into account the version of darwin, and just blindly installs with the assumption that it will work. If you're running an outdated version of osx, loading the darwin prebuilds will crash without an error message.

cacieprins avatar Nov 13 '23 15:11 cacieprins