Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@Andark
Copy link

Andark commented Jan 9, 2016

Hi, I followed these steps list above and rebuild successfully. But when I run the electron app, I got an error:Uncaught Error:
A dynamic link library (DLL) initialization routine failed.
?\D:\Shadow\Node\electron-start\node_modules\sqlite3\lib\binding\node-v47-win32-x64\node_sqlite3.node.

Below is my code in index.html ( I haven't written any code in other files):

    <h1>Hello World!</h1>
    We are using node  <script>document.write(process.versions.node)</script>,
    Chrome                   <script>document.write(process.versions.chrome)</script>,
    and Electron            <script>document.write(process.versions.electron)</script>.

    <hr/>

    <script>
        var sqlite3 = require('sqlite3');
        // var db = new sqlite3.Database('D:\Database\SQLite\Seven.db3');
        //
        // db.serialize(function() {
        //     db.each("SELECT point_no,point_name FROM Utb_points", function(err, row) {
        //       console.log(row.point_no + ": " + row.point_name);
        //     });
        // });
        //
        // db.close();
    </script>

I don't have any idea about this error, please help me to point out what the error is. This problem has troubled me for a long time.

@c1rdan
Copy link

c1rdan commented Apr 26, 2016

Based on my latest instalation it should be electron-v0.37-win32-x64 instead of node-v47-win32-x64

@robinne
Copy link

robinne commented Apr 30, 2016

Thank you for this concise summary. I also was running into electron looking for electron-v0.37-win32-x64, but the directory that was getting created under sqlite3 was node-v47-win32-x64. I've spent hours trying to resolve this. I finally came across the original post that you have summarized for windows. I think I kept getting just one thing wrong every time I would try to run various commands. My final process was to install sqlite3 (did not need to install nan, it was already installed there), and then run the 3 command, changing both my electron version and my directories to be electron-v0.37-win32-x64. To find my electron version I used <script>document.write(process.versions.electron)</script> in index.html. thanks again!

@paula23andrea
Copy link

paula23andrea commented Dec 15, 2016

Hi!
I'm trying to run my electron app in Windows, but sqlite3 is a real headache.
When I run
node-gyp rebuild --target=1.4.0 --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

I get this error:

gyp info it worked if it ends with ok
gyp info using node-gyp@3.4.0
gyp info using node@6.9.2 | win32 | x64
gyp http GET https://atom.io/download/atom-shell/v1.4.0/iojs-v1.4.0.tar.gz
gyp http 200 https://atom.io/download/atom-shell/v1.4.0/iojs-v1.4.0.tar.gz
gyp http GET https://atom.io/download/atom-shell/v1.4.0/SHASUMS256.txt
gyp http GET https://atom.io/download/atom-shell/v1.4.0/win-x86/iojs.lib
gyp http GET https://atom.io/download/atom-shell/v1.4.0/win-x64/iojs.lib
gyp http 200 https://atom.io/download/atom-shell/v1.4.0/SHASUMS256.txt
gyp http 200 https://atom.io/download/atom-shell/v1.4.0/win-x64/iojs.lib
gyp http 200 https://atom.io/download/atom-shell/v1.4.0/win-x86/iojs.lib
gyp info spawn C:\Python27\python.EXE
gyp info spawn args [ 'C:\\Users\\daniel\\AppData\\Roaming\\npm\\node_modules\\n
ode-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\daniel\\Downloads\\tm-electron-tests\\node_mod
ules\\sqlite3\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\daniel\\AppData\\Roaming\\npm\\node_modules\\n
ode-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\daniel\\.node-gyp\\iojs-1.4.0\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\daniel\\.node-gyp\\iojs-1.4.0'
,
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\daniel\\AppData\\Roaming\\npm\\
node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=iojs.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\daniel\\Downloads\\tm-electr
on-tests\\node_modules\\sqlite3',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Users\\daniel\\Downloads\\tm-electron-tests\\node_mod
ules\\sqlite3\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp ERR! build error
gyp ERR! stack Error: Command failed: reg query "HKLM\Software\Microsoft\MSBuild
\ToolsVersions" /s /reg:32
gyp ERR! stack 'reg' is not recognized as an internal or external command,
gyp ERR! stack operable program or batch file.
gyp ERR! stack
gyp ERR! stack Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++
 2008+ installed?
gyp ERR! stack     at C:\Users\daniel\AppData\Roaming\npm\node_modules\node-gyp\
lib\build.js:134:25
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:213:5)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_proces
s.js:226:5)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\daniel\\AppDa
ta\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=
1.4.0" "--arch=x64" "--target_platform=win32" "--dist-url=https://atom.io/downlo
ad/atom-shell" "--module_name=node_sqlite3" "--module_path=../lib/binding/electr
on-v1.4-win32-x64"
gyp ERR! cwd C:\Users\daniel\Downloads\tm-electron-tests\node_modules\sqlite3
gyp ERR! node -v v6.9.2
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok

I really have researched a lot.
When I run the app, i get this:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\daniel\Downloads\tm-electron-tests\node_modules\sqlite3\lib\binding\electron-v1.4-win32-x64\node_sqlite3.node
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\daniel\Downloads\tm-electron-tests\node_modules\sqlite3\lib\sqlite3.js:4:15)

Many thanks!!

@jaidirectdsn
Copy link

jaidirectdsn commented Dec 27, 2016

@paula23andrea, i having the same issue. Do you got a solution for this one? if yes please share it.

TryGhost/Ghost#7808

@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

JohnTendik commented Jan 2, 2017

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

JohnTendik commented Jan 8, 2017

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

Fraganya commented Jan 24, 2017

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

@biroplane
Copy link

biroplane commented Feb 17, 2017

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

chandra911 commented Feb 28, 2017

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

heffrey78 commented Jun 7, 2017

@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

JeevanJain commented Jun 12, 2017

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

michaelbrandt commented Jul 19, 2017

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