Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron app crashing with latest better-sqlite3 #1062

Closed
jayakrishnankp opened this issue Sep 11, 2023 · 8 comments
Closed

Electron app crashing with latest better-sqlite3 #1062

jayakrishnankp opened this issue Sep 11, 2023 · 8 comments

Comments

@jayakrishnankp
Copy link

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 jayakrishnankp changed the title Electron app crash with latest better-sqlite3 Electron app crashing with latest better-sqlite3 Sep 11, 2023
@neoxpert
Copy link
Contributor

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 #1044 (comment).

@jayakrishnankp
Copy link
Author

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.

@neoxpert
Copy link
Contributor

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.

@jayakrishnankp
Copy link
Author

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.

@tetap
Copy link

tetap commented Sep 21, 2023

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

@TylerTemp
Copy link

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

Saved my life

@tetap
Copy link

tetap commented Oct 15, 2023

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

@cacieprins
Copy link

cacieprins commented Nov 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants