Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maximilian-lindsey/9de273f72c1ba4aa62d6 to your computer and use it in GitHub Desktop.
Save maximilian-lindsey/9de273f72c1ba4aa62d6 to your computer and use it in GitHub Desktop.
SQLite3 Electron windows integration

SQLite3 Electron windows integration

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.

@Fraganya
Copy link

@JohnTendik thanks a lot...the issue was giving me a headache

@biroplane
Copy link

hello! how can i make it work on mac? sqlite3 module fails either on building on mac. did anyone solved this issue?
thx!

@chandra911
Copy link

while running SQLite integration with windows
facing difficultiies with $ node-gyp
bash: node-gyp: command not found
issue. Please suggest on this issue.

@heffrey78
Copy link

@JohnTendik thank you! I've been through a lot of instructions that were similar, that failed. I think it was bluebird that made the difference for me.

@JeevanJain
Copy link

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: 1
gyp 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

@michaelbrandt
Copy link

Maybe this could help some people

Problem: bash: node-gyp: command not found
Solution: npm install -g node-gyp

Problem: how can i make it work on Mac?
Solution:

git clone the starter electron app
npm install --save electron-rebuild
npm install bluebird /* (required module for electron-rebuild that doesn't come packed for some reason) */
npm install --save sqlite3

cd node_modules/sqlite3
npm install nan

npm run prepublish && node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.7-darwin-x64 && node-gyp rebuild --target=1.7.0 --arch=x64 --target_platform=darwin --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.7-darwin-x64

You have to change the version numbers according to your needs.

@Chelo21
Copy link

Chelo21 commented Apr 26, 2020

Solución: (electron y

npm install electron -save-dev
npm install electron-rebuild --save-dev
npm install sqlite3

en el "package.json" agregar:

"rebuild": "electron-rebuild -f -w sqlite3"

===================
npm run rebuild

=================
y listo.
Por las dudas en los ".js":
var sqlite3 = require('sqlite3').verbose();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment