I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command
npm install --save sqlite3
but it
I encounter this error too. Here is how i solve it:
npm install --save-dev electron-rebuild
then:
./node_modules/.bin/electron-rebuild
from: https://electronjs.org/docs/tutorial/using-native-node-modules
ps: While it's on rebuilding, don't use npm start
to lanch the electron app. Otherwise the rebuild process would fail.
It works for me in version 3 and 4, unfortunately NOT version 5. See the sqlite3 documentation for details: https://www.npmjs.com/package/sqlite3#custom-builds-and-electron or otherwise run the following line: npm install sqlite3 --runtime=electron --target=4.0.0 --dist-url=https://atom.io/download/electron
A simpler solution:
npm i electron-rebuild --save-dev
./node_modules/.bin/electron-rebuild
(or .\node_modules\.bin\electron-rebuild.cmd
on windows)PS: v47 is my version, be careful to choose the good one (in your case v45)
By far the easiest way to use SQLite with electron is with electron-builder
.
First, add a postinstall step in your package.json:
"scripts": {
"postinstall": "install-app-deps"
...
}
and then install the necessary dependencies and build:
npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall
electron-builder will build the native module for your platform, with the correct name for the Electron binding; and you can then require
it in code as normal.
See my github repo and blog post - it took me quite a while to figure this out too.