I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command
npm install --save sqlite3
but it
npm install --save sqlite3
npm install --save-dev electron-rebuild
Then, in the scripts of your package.json, add this line:
"scripts": {
"postinstall": "electron-rebuild",
...
},
Then just re-install to trigger the post-install:
npm install
Works flawlessly for me in a complex use case also involving electron-builder, electron-webpack and sequelize.
It works in electron-webpack's dev mode and in production mode for both Windows and Linux.
I was having same problem. Tried everything and atlast this worked for me :-
npm install --save sqlite3
npm install --save electron-rebuild
npm install --save electron-prebuilt
.\node_modules\.bin\electron-rebuild.cmd
This will create "electron-v1.3-win32-x64" folder in .\node_modules\sqlite3\lib\binding\ location which is used by electron to use sqlite3.
Just start application and you will be able to use sqlite3 now.
Have a look at a similar answer here
TL;DR
cd .\node_modules\sqlite3
npm install nan --save
npm run prepublish
node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.3-win32-x64
node-gyp rebuild --target=1.3.2 --arch=x64 --target_platform=win32 --dist-url=http://electron.atom.io/ --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.3-win32-x64
You can manually build the native modules using visual studio.
In package.json create a script. "scripts": { "postinstall": "install-app-deps" }
then run the script.
I would not recommend the native node sqlite3 module. It requires being rebuild to work with electron. This is a massive pain to do - At least I can never get it to work and their a no instructions to for rebuilding modules on windows.
Instead have a look at kripken's 'sql.js' module which is sqlite3 that has been compiled 100% in JavaScript. https://github.com/kripken/sql.js/
Two aspects are to be considered here:
NODE_PATH
: this lets electron know where to find your modules (see this answer for a thorough explanation) And checkout the following questions, that ask the same thing:
My tip would be to give lovefield (by Google) a try.