WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.36k stars 394 forks source link

App is throwing the error while running electron 14.0.0 and better-sqlite3 #694

Closed akash07k closed 2 years ago

akash07k commented 3 years ago

Description: I'm using electron 14.0.0 and latest version of better-sqlite3 package. However, when I try to run my app I get the following error: Compiling Renderer Code[13984:0903/144946.475:ERROR:crashpad_client_win.cc(808)] not connected And my app exits. Steps to reproduce:

  1. use npx create-electron-app --template="webpack to create/initialize a fresh new electron app with ElectronForge.
  2. Now execute npm install better-sqlite3.
  3. Require better-sqlite3 in your main.js file: (let db = require("better-sqlite3");)
  4. Now execute npm start and observe.
  5. The app will throw the error such as: Compiling Renderer Code[13984:0903/144946.475:ERROR:crashpad_client_win.cc(808)] not connected

(This error doesn't come if we use Electron 13.3.0)

@JoshuaWise

Prinzhorn commented 3 years ago

I can reproduce this with a vanilla project as well (without all the bells and whistles of create-electron-app). This error seems to come up frequently with other native modules as well https://github.com/search?o=desc&q=_ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeE&s=&type=Issues

I am kind of confused, because I can't seem to make npm rebuild or electron-rebuild actually make it rebuild from scratch. And since there is no prebuild for Electron 14 I have no idea what it's actually installing?

So I'm not sure on which end this needs to be fixed.

Prinzhorn commented 3 years ago

I might be entirely lost, but maybe this is related to the fact that both Electron 13 and 14 use ABI 89. That means it pulls the prebuild for ABI 89 but it was compiled for Electron 13. The prebuilds need to be for a given Electron version, not ABI version. There needs to be a prebuild for 13 AND for 14, not a single 89. Does that make sense? Maybe this was the first Electron major release without ABI bump, at least since better-sqlite3 has prebuilds (see https://github.com/electron/node-abi/blob/master/abi_registry.json).

Edit:

Currently:

better-sqlite3-v7.4.3-electron-v89-linux-x64.tar.gz

Future?

better-sqlite3-v7.4.3-electron-v13-linux-x64.tar.gz
better-sqlite3-v7.4.3-electron-v14-linux-x64.tar.gz

But I don't really know a lot about this. Maybe the ABI version is the only thing relevant for compatibility? If so, then why doesn't it work?

akash07k commented 3 years ago

Ya, you are right. I too agree with you. It may be possible that it may need to be compiled/built for electron V14 in order to make it work but I don't know that how to acomplish it.

I might be entirely lost, but maybe this is related to the fact that both Electron 13 and 14 use ABI 89. That means it pulls the prebuild for ABI 89 but it was compiled for Electron 13. The prebuilds need to be for a given Electron version, not ABI version. There needs to be a prebuild for 13 AND for 14, not a single 89. Does that make sense? Maybe this was the first Electron major release without ABI bump, at least since better-sqlite3 has prebuilds (see https://github.com/electron/node-abi/blob/master/abi_registry.json).

Edit:

Currently:

better-sqlite3-v7.4.3-electron-v89-linux-x64.tar.gz

Future?

better-sqlite3-v7.4.3-electron-v13-linux-x64.tar.gz
better-sqlite3-v7.4.3-electron-v14-linux-x64.tar.gz

But I don't really know a lot about this. Maybe the ABI version is the only thing relevant for compatibility? If so, then why doesn't it work?

Prinzhorn commented 3 years ago

This could potentially be fixed by upgrading prebuild-install https://github.com/JoshuaWise/better-sqlite3/blob/master/package.json#L14

Because of https://github.com/electron/node-abi/pull/104 but it's not in yet https://github.com/prebuild/prebuild-install/blob/c96c526d360b2e8ce0ece5b9e3c06b13082ea74e/package.json#L29

Manually doing npm i node-abi@2.30.1 doesn't fix it, so yeah. Maybe that needs to happen in the better-sqlite3 CI first to create new prebuilds.

akash07k commented 3 years ago

Cool, so how can I incorporate the fix at my side so that I can run electron 14 with better-sqlite3?

This could potentially be fixed by upgrading prebuild-install https://github.com/JoshuaWise/better-sqlite3/blob/master/package.json#L14

Because of electron/node-abi#104 but it's not in yet https://github.com/prebuild/prebuild-install/blob/c96c526d360b2e8ce0ece5b9e3c06b13082ea74e/package.json#L29

Manually doing npm i node-abi@2.30.1 doesn't fix it, so yeah. Maybe that needs to happen in the better-sqlite3 CI first to create new prebuilds.

rayzorben commented 3 years ago

Is there anything that can be done in the meantime? I tried going back to electron@13.2.3 but that doesn't seem to be working now either.

barbalex commented 2 years ago

I have the same problem. When using electron v14 this happens when upgrading better-sqlite3 beyond v7.4.0. It seems that adding prebuilt binaries may have caused this: https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.4.1 Could it be that a node mismatch is created with electron?

akash07k commented 2 years ago

Still no update on this. Sadly I can't use electron 14 due to this issue

On 9/9/21, Alexander Gabriel @.***> wrote:

I have the same problem. When using electron v14 this happens when upgrading better-sqlite3 beyond v7.4.0. It seems that adding prebuilt binaries may have caused this: https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.4.1 Could it be that a node mismatch is created with electron?

-- You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub: https://github.com/JoshuaWise/better-sqlite3/issues/694#issuecomment-916060018

barbalex commented 2 years ago

@akash07k have you tried using v7.4.0? That is the last version that works for me. If the reason is a node mismatch then probably versions beyond 7.4.0 will not work in lower versions of electron either.

akash07k commented 2 years ago

No, not tried, but going to try now.

@akash07k have you tried using v7.4.0? That is the last version that works for me. If the reason is a node mismatch then probably versions beyond 7.4.0 will not work in lower versions of electron either.

akash07k commented 2 years ago

Yes bro, I tried with 7.4.0. It works fine. @JoshuaWise Any update on this?

@akash07k have you tried using v7.4.0? That is the last version that works for me. If the reason is a node mismatch then probably versions beyond 7.4.0 will not work in lower versions of electron either.

barbalex commented 2 years ago

I am not sure if the issue is with better-sqlite3 or with the build tools used with electron.

akash07k commented 2 years ago

yeah

On 9/10/21, Alexander Gabriel @.***> wrote:

I am not sure if the issue is with better-sqlite3 or with the build tools used with electron.

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/JoshuaWise/better-sqlite3/issues/694#issuecomment-916997741

Tenison commented 2 years ago
//First Uninstall  better-sqlite3
npm uninstall better-sqlite3
//use version 7.4.0
npm install better-sqlite3@7.4.0 

npm uninstall electron
//use version 13
npm install electron@~13.4.0

//install electron-rebuild
npm i -D electron-rebuild
// Delete both "node-modules" folder, as well as the "packages-lock.json"
//reinstall using
npm i
//rebuild packages
./node_modules/.bin/electron-rebuild    //run for mac 
.\node_modules\.bin\electron-rebuild.cmd  //run for windows

/////that solved my problem

///Use electron-packager to build your app
npm install -g electron-packager --save-dev
npx electron-packager <appDirectory> appName --overwrite --asar --electron-version=13.4.0 --platform=win32 --arch=x64 --prune=true --out=release-builds --icon=./build/icon.ico"
akash07k commented 2 years ago

No, this is not the way for the users who want to use electron 14 with their apps. Although as of now I'm using better-sqlite3 7.4.0 for the time being

//First Uninstall  better-sqlite3
npm uninstall better-sqlite3
//use version 7.4.0
npm install better-sqlite3@7.4.0 

npm uninstall electron
//use version 13
npm install electron@~13.4.0

//install electron-rebuild
npm i -D electron-rebuild
// Delete both "node-modules" folder, as well as the "packages-lock.json"
//reinstall using
npm i
//rebuild packages
./node_modules/.bin/electron-rebuild    //run for mac 
.\node_modules\.bin\electron-rebuild.cmd  //run for windows

/////that solved my problem

///Use electron-packager to build your app
npm install -g electron-packager --save-dev
npx electron-packager <appDirectory> appName --overwrite --asar --electron-version=13.4.0 --platform=win32 --arch=x64 --prune=true --out=release-builds --icon=./build/icon.ico"
Tenison commented 2 years ago

Yes definitely, but until the issue is resolved, this is the solution I'm using. Did yours work with electron 14, because mine does not

akash07k commented 2 years ago

Yes, better-sqlite3 7.4.0 works well with electron 14.

Yes definitely, but until the issue is resolved, this is the solution I'm using. Did yours work with electron 14, because mine does not

Tenison commented 2 years ago

Yes, better-sqlite3 7.4.0 works well with electron 14.

Yes definitely, but until the issue is resolved, this is the solution I'm using. Did yours work with electron 14, because mine does not

KK.. I will try it out

lazytyper commented 2 years ago

I've been trying to integrate better-sqlite3 with Electron, I've found this solution:

https://ishwar-rimal.medium.com/integrating-sqlite3-in-electron-project-build-with-electron-forge-6d4d634b8648

But, it seems it to work on Windows, but I'm using Linux.

I also found this issue posted on electron-rebuild:

electron-rebuild properly rebuilds better-sqlite3 on Windows, but skips the rebuild on Linux https://github.com/electron/electron-rebuild/issues/591

mceachen commented 2 years ago

@JoshuaWise I poked at this a bit just now.

prebuild-install can be forced to rebuild by setting the environment variable npm_config_build_from_source=true, but using the currently-released version (6.0.1), I still got

(node:2357177) UnhandledPromiseRejectionWarning: Error: The module '/tmp/.mount_PhotoS9hayLP/resources/app.asar.unpacked/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 89. 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`).

I cloned better-sqlite3 into a local directory, ran npx ncu -u which pulled in "prebuild-install": "^6.1.4", changed my package.json to point to that new directory, and everything looks good.

TL;DR: please upgrade your prebuild-install dependency. #702 should take care of it.

(Also, TIL that prebuild now recommends transitioning to prebuildify paired with node-gyp-build. More context here)

cloverich commented 2 years ago

I adapted renkei's workaround slightly to directly call npm rebuild providing the target versions. I don't really understand how it uses the electron version properly ¯_(ツ)_/¯

#!/bin/bash

# Adapted from:
# https://github.com/electron/electron-rebuild/issues/591

# Electron's version.
# example of electron -v --> v15.1.1
export npm_config_target=$(npx electron -v)

# The architecture of Electron, see https://electronjs.org/docs/tutorial/support#supported-platforms
# for supported architectures.
export npm_config_arch=x64
export npm_config_target_arch=x64

# Download headers for Electron.
export npm_config_disturl=https://electronjs.org/headers

# Tell node-pre-gyp that we are building for Electron.
export npm_config_runtime=electron

# Tell node-pre-gyp to build module from source code.
export npm_config_build_from_source=true

HOME=~/.electron-gyp npm rebuild better-sqlite3
cloverich commented 2 years ago

Towards @mceachen 's upgrade fix I am betting build from source being ignored patch was the culprit

JoshuaWise commented 2 years ago

This should be fixed in v7.4.4.

Prinzhorn commented 2 years ago

Can anyone confirm this is working for them? For me I still can't get electron-rebuild to make to correct version for Electron 14 or 15. And my observations above seem to still hold true that the entire chain of dependencies is still borked because it relies on an outdated node-abi version. That means prebuild needs an update as it still points at the old node-abi. And after that has happened better-sqlite3 needs to push a new update to trigger another run of builds. Right?

mceachen commented 2 years ago

Electron 15 is still broken. See https://github.com/JoshuaWise/better-sqlite3/issues/713#issuecomment-951166197

m4heshd commented 2 years ago

@Prinzhorn No need for a rebuild. We simply have to wait till app-builder-bin is fixed. (https://github.com/electron-userland/electron-builder/issues/6352#issuecomment-968363064)

Scratch that. Just need prebuild-install updated and all good. Prebuilds are still good. No need for a rebuild.

barbalex commented 2 years ago

Version 7.4.5 works for me. Thanks!

JoshuaWise commented 2 years ago

Thanks @barbalex. Closing this, but would appreciate more confirmations that it is working for people in 7.4.5

Prinzhorn commented 2 years ago

I recently migrated to Electron 16 and it went smooth. So I can confirm that it works with the latest Electron + better-sqlite3. Can't speak for older combinations.

barbalex commented 2 years ago

I just got this again in two projects after having updated to v7.4.6 and electron 16.0.6. Reverting to v7.4.5 solved the issue

YOSSTM commented 2 years ago

I just want to add something , it works at build time but in the release didn't work .I'm using electron 15

Johanbos commented 1 year ago

I've encountered this issue with Electron 26 & better-sqlite3 v8.5.x. Going to see which downgrade works again :(

xchgrbprsp commented 1 year ago

I've encountered this issue with Electron 26 & better-sqlite3 v8.5.x. Going to see which downgrade works again :(

I just got the same issue with Electron 26.1.0. Had to downgrade to 25.4.0 and it worked again.