This guide is based on the very informative discussion in this article: Using node_sqlite3 with Electron
Install sqlite3
npm install sqlite3 --save
Navigate into the sqlite3 module folder
cd node_modules/sqlite3
Install nan locally into the sqlite3 folder (you will need it for the next step)
npm install nan@~2.1.0 --save
Prebulish the module:
npm run prepublish
Start compilation by setting the module path to the correct version, in this case node-v47-win32-x64
. It is located in your sqlite3 folder.
node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/node-v47-win32-x64
Finish compilation by setting your build to the correct target
version. You will find the target
version of your Electron-App in the version
file in the root folder of your Electron directory.
node-gyp rebuild --target=0.36.0 --arch=x64 --target_platform=win32 --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/node-v47-win32-x64
Now you can use sqlite3 in your Electron app.
getting error after
node-gyp rebuild
C:\Users\Jeevan.node-gyp\iojs-1.6.10\x64\iojs.lib : fatal error LNK1127: library is corrupt [F:\wirecamp\hello-electron-with-pouchdb\nod
e_modules\sqlite3\build\node_sqlite3.vcxproj]
gyp ERR! build error
gyp ERR! stack Error:
C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
failed with exit code: 1gyp ERR! stack at ChildProcess.onExit (C:\Users\Jeevan\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:191:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.10586
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Jeevan\AppData\Roaming\npm\node_modules\npm\node_modules\node-gy
p\bin\node-gyp.js" "rebuild" "--target=1.6.10" "--arch=x64" "--target_platform=win32" "--dist-url=http://electron.atom.io/" "--module_na
me=node_sqlite3" "--module_path=../lib/binding/electron-v1.6-win32-x64"
gyp ERR! cwd F:\wirecamp\hello-electron-with-pouchdb\node_modules\sqlite3
gyp ERR! node -v v6.10.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok