Webpack should copy and use the Electron bindings from
node_modules\sqlite3\lib\binding\electron-v7.1-win32-x64\node_sqlite3.node
Webpack instead copies the _original_ Node bindings and loads those, giving the usual Error: The module was compiled against a different Node.js version, with the following path:
node_modules\sqlite3\lib\binding\node-v79-win32-x64\node_sqlite3.node
Configure Forge with webpack (I also use TypeScript), install sqlite3, import it in a script, and run the start script.
None
I managed to get a workaround by importing SQLite in Electron's main process and using Electron's IPC modules to communicate between the processes. But I'm not sure if this is a proper solution, especially if a lot of data is being sent over IPC from querying the database.
And could the reason that this work be because of the difference between the Node bundle used by the main process (i.e. because it uses the sqlite module in node_modules), and the "browser" bundle used by the renderer process?
I get this same error in both the renderer and main process
@nickvoosten Weird, it worked for me albeit I’m using better-sqlite3 → https://github.com/electron-userland/electron-forge/issues/1224#issuecomment-606649565
Regarding your 2nd question, I think all calculations should be made in the “background process”. I just read this awesome blog post → https://jlongster.com/secret-of-good-electron-apps which links to https://github.com/jlongster/electron-with-server-example
It highlights the use of performing heavy applications in a “background process” for a proper local Electron application which is fast & works offline. I think what you are doing is probably right but I’m still a noob when it comes to Electron. I think the blog above shall answer all your questions though :)
Sorry but i can't fix this.
Even with a fresh install :
my-new-app/node_modules/sqlite3/lib/binding/node-v79-darwin-x64/node_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 79. This version of Node.js requires
NODE_MODULE_VERSION 76. Please try re-compiling or re-installing
// src/index.ts <= main process
import { Database } from "sqlite3";
import { app, BrowserWindow } from "electron";
declare const MAIN_WINDOW_WEBPACK_ENTRY: any;
const test = new Database(":memory:"); // Causes the error
I tried a lot of potential solutions, without success.
@cyril-barragan that means you have used the wrong version of Node. I use v10.15.1 of Node to compile & I use https://github.com/Schniz/fnm to switch Node versions. You have to compile using a certain version which can be found in https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/troubleshooting.md or you have to search some issues.
Thank you for your quick answer.
I deleted brew node, yarn, nvm. Tried fnm with the version your recommended, tried to delete ~/.node-gyp ~/.npm reinstall node-gyp globally. I also tried official node installer. I created new projects at each step, restarted terminal in order to source the last path modifications, try npm run rebuild. Still no luck.
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 76. Please try re-compiling or re-installing
Did you use electron-rebuild to build it? Follow this guide. Also, check out that issue completely. I found my solution from there
Yes I did but no luck either, I even set it as postinstall script.
I ended up not using electron-forge and using only electron-webpack with electron-rebuild as postinstall script.
@cyril-barragan In case you ever give electron-forge a shot again, then check this out
I found a working solution with electron-forge & better-sqlite3 & correct bindings are used :)