Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • 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.

@GISConsortium
Copy link

GISConsortium commented Jan 2, 2017

Hi there, I am new to electron. I am facing an issue on running the last command, i.e.

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
I was not able to compile sqlite package for the electron package V1.4.12 and node version v6.9.1 I amusing Windows 7 professional.
The error I am facing is as follows:

Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
unpack_sqlite_dep
sqlite3.cc
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(91) : see
declaration of 'v8::Object'
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3064): error C2989:
'v8::Array' : class template has already been declared as a non-class template
[D:\Nitin\NodeJS\Final91216\electron\NodeJSSQLite\node_modules\sqlite3\build\n
ode_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(71) : see
declaration of 'v8::Array'

C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3418): error C2238:
unexpected token(s) preceding ';' [D:\Nitin\NodeJS\Final91216\electron\NodeJSS
QLite\node_modules\sqlite3\build\node_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3419): error C2143:
syntax error : missing ';' before '<' [D:\Nitin\NodeJS\Final91216\electron\Nod
eJSSQLite\node_modules\sqlite3\build\node_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3419): error C4430:
missing type specifier - int assumed. Note: C++ does not support default-int [
D:\Nitin\NodeJS\Final91216\electron\NodeJSSQLite\node_modules\sqlite3\build\nod
e_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3420): error C2238:
unexpected token(s) preceding ';' [D:\Nitin\NodeJS\Final91216\electron\NodeJSS
QLite\node_modules\sqlite3\build\node_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3428): error C2061:
syntax error : identifier 'Value' [D:\Nitin\NodeJS\Final91216\electron\NodeJSS
QLite\node_modules\sqlite3\build\node_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3432): error C2061:
syntax error : identifier 'Value' [D:\Nitin\NodeJS\Final91216\electron\NodeJSS
QLite\node_modules\sqlite3\build\node_sqlite3.vcxproj]
C:\Users\ky29991.node-gyp\iojs-1.4.12\deps\v8\include\v8.h(3432): fatal error
C1003: error count exceeds 100; stopping compilation [D:\Nitin\NodeJS\Final9121
6\electron\NodeJSSQLite\node_modules\sqlite3\build\node_sqlite3.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\ky29991\AppData\Roaming\npm
node_modules\node-gyp\lib\build.js:276: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_proces
s.js:215:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\ky29991\AppD
ata\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--target
=1.4.12" "--arch=x64" "--target_platform=win32" "--dist-url=https://atom.io/down
load/atom-shell" "--module_name=node_sqlite3" "--module_path=../lib/binding/node
-v48-win32-x64"
gyp ERR! cwd D:\Nitin\NodeJS\Final91216\electron\NodeJSSQLite\node_modules\sqlit
e3
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok

Thanking you,
Nitin Kandpal

@JohnTendik
Copy link

I'm actually having this exact issue as well. Tried all the options, none worked. I'm guessing we're all on Node v6? Someone mentioned that node v6 just doesn't work, maybe downgrading might solve the issue?

@JohnTendik
Copy link

Here is what worked for me:

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.4-win32-x64 && node-gyp rebuild --target=1.4.13 --arch=x64 --target_platform=win32 --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.4-win32-x64

electron v1.4.13 currently, so change the target to your version. Also change the target platform & forlder names if you want to compile for mac or *nix

GL!

@showrav017
Copy link

showrav017 commented Jan 13, 2017

@JohnTendik, Thanks a lot.

@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