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-rebuild properly rebuilds better-sqlite3 on Windows, but skips the rebuild on Linux #591

Closed
renkei opened this issue Jan 26, 2021 · 1 comment

Comments

@renkei
Copy link

renkei commented Jan 26, 2021

Node.js 14.15.4
electron 12.0.0-beta.18
electron-rebuild 2.3.4
better-sqlite3 7.1.2

On Windows, better-sqlite3 is built against Node 14 (windows-build-tools with Python 2.7 are properly installed) and rebuilt against electron 12 using electron-rebuild. The resulting electron app works as expected.

On Linux (Arch Linux, same versions as above) better-sqlite3 is not built but installed via a prebuild binary. When I try to start the electron app with that binary I get the expected NODE_MODULE_VERSION mismatch error:

Error: The module '/home/renkei/Development/MyApp/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using NODE_MODULE_VERSION 85.
This version of Node.js requires NODE_MODULE_VERSION 87.
Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`).

So, I run electron-rebuild like I do on Windows but on Linux nothing happens. After the log message Searching dependeny tree
I get immediately Rebuild Complete. The same happens when I use option -f or -w better-sqlite3 or both.

When I export DEBUG=* for more debug output I get without option -f:

Searching dependency tree 
electron-rebuild skipping: better-sqlite3 as it is already built +52ms
✔ Rebuild Complete

and with option -f:

Searching dependency tree 
Building module: better-sqlite3, Completed: 0 
electron-rebuild assuming is prebuild powered: better-sqlite3 +0ms
electron-rebuild triggering prebuild download step: better-sqlite3 +0ms
Building module: better-sqlite3, Completed: 0 
electron-rebuild built: better-sqlite3 +106ms
✔ Rebuild Complete

Any idea, why the the recompile step is not properly triggered?

@renkei
Copy link
Author

renkei commented Jan 30, 2021

I've solved this with a postinstall script in package.json that runs electron-rebuild on Windows and a self-made shell script on Linux that executes npm install better-sqlite3 again, but this time npm is re-configured to build directly for electron, like suggested by the electron documentation as an alternative to electron-rebuild, works perfectly for me.

#!/bin/bash

# Electron's version.
export npm_config_target=$1

# 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

# Install all dependencies, and store cache to ~/.electron-gyp.
HOME=~/.electron-gyp npm install better-sqlite3

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

No branches or pull requests

1 participant