m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
137 stars 27 forks source link

Version 9.5.0 prebuild for Electron 29 uses Node 18, not 20 #92

Closed DCzajkowski closed 2 months ago

DCzajkowski commented 2 months ago

Version 9.5.0 of this package contains a prebuilt version for Electron 29. ~However, it is built for Node 18, but Electron 29 uses Node 20.9.0.~ (see update below)

Prebuilding with wrong Node version causes this error:

Error: The module '<path>/node_modules/better-sqlite3-multiple-ciphers/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 121. 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/node_init:2:2214)
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1343:18)
    at Object.func [as .node] (node:electron/js2c/node_init:2:2214)
    at Module.load (node:internal/modules/cjs/loader:1098:32)
    at Module._load (node:internal/modules/cjs/loader:945:12)
    at Function.c._load (node:electron/js2c/node_init:2:13672)
    at Module.require (node:internal/modules/cjs/loader:1122:19)
    at require (node:internal/modules/helpers:130:18)
    at new Database (<path>/node_modules/better-sqlite3-multiple-ciphers/lib/database.js:52:11)
    at Database (<path>/node_modules/better-sqlite3-multiple-ciphers/lib/database.js:11:10) {
  code: 'ERR_DLOPEN_FAILED'
}

Of course, manual rebuild is possible, but it defies the purpose of prebuilding.

DCzajkowski commented 2 months ago

Update: I've noticed it's not a problem of the GitHub Action using Node 18, but the problem is somewhere else.

By downgrading to Electron 29.0.0, I can see better-sqlite3-multiple-ciphers uses NODE_MODULE_VERSION 123 (Node 21.x), but should be using NODE_MODULE_VERSION 121 (Node 20.x).

m4heshd commented 2 months ago

Hi,

Did you make sure to rebuild against Electron after the installation?

DCzajkowski commented 2 months ago

If I rebuild after installation everything works fine :)

However, I thought a rebuild should not be necessary, since the pre-built version is available for my Electron/OS/arch combo on npm. Is it not how it is supposed to work?

m4heshd commented 2 months ago

However, I thought a rebuild should not be necessary, since the pre-built version is available for my Electron/OS/arch combo on npm. Is it not how it is supposed to work?

It's actually not rebuilding (depends on the tool you use). It still downloads the prebuilt version.

The issue you're facing is that when you install a native dependency, what NPM is seeing is your locally installed Node runtime, not the Electron runtime. So it naturally finds the prebuilt binary for that particular runtime. You have to tell it manually to download the prebuilt binary (or rebuild on-host) against the Electron runtime. If you use something like electron-builder, you can use the electron-builder install-app-deps command to download the prebuilt binaries compiled for the particular Electron version you're using.

Closing the issue.