Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Electron SQLite3 Integration

Electron SQLite3 Integration

When trying to use the node-sqlite3 module in Electron I got the error:

Error: Cannot find module '/path/to/my/application/node_modules/sqlite3/lib/binding/electron-v1.4-linux-x64/node_sqlite3.node'

Using Ubuntu 16.04 with Node 7.1.0 and Electron 1.4.12.

I read the following:

And managed to solve things by:

Install node-gyp globally

npm install -g -save node-gyp

Install sqlite3

npm install --save sqlite3

Navigate into the sqlite3 module folder

cd node_modules/sqlite3

Install the modules dependencies

npm install

Prebulish the module

npm run prepublish

Check which binding exists, In this case node-v51-linux-x64

ls lib/binding/

Start compilation by setting the module path to the correct binding/version

node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/node-v51-linux-x64

Finish compilation by setting your build to the correct target version. You will find the target version of your Electron app in the package.json file in the root folder of your Electron directory, e.g: "electron": "1.4.12".

node-gyp rebuild --target=1.4.12 --arch=x64 --target_platform=linux --dist-url= --module_name=node_sqlite3 --module_path=../lib/binding/node-v51-linux-x64

Rename the binding folder so that it is the same as the module that it could not find in the error

mv lib/binding/node-v51-linux-x64/ lib/binding/electron-v1.4-linux-x64/

Now you can use sqlite3 in your Electron app.

Further example:

node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/[DIR]
node-gyp rebuild --target=[ELEC-VER] --arch=[ARCH] --target_platform=[PLATFORM] --dist-url= --module_name=node_sqlite3 --module_path=../lib/binding/node-[NODE-VER]-[PLATFORM]-[ARCH]

Placeholder   Value
[DIR]         The name of the directory called "Can not find" in the preliminary survey
[ELEC-VER]    Version of Electron.
[ARCH]        In the case of 32Bit ia32
              In the case of 64Bit x64
[PLATFORM]    In the case of Windows win32
              In the case of Mac darwin
              In the case of Linux linux
[NODE-VER]    ls lib/binding/ => in this case `node-v51-linux-x64`

This comment has been minimized.

Copy link

@jonataswalker jonataswalker commented Jan 20, 2017

Definitely the only way I got this thing working.

Thanks for sharing this!


This comment has been minimized.

Copy link
Owner Author

@craigvantonder craigvantonder commented Mar 8, 2017

@jonataswalker Pleasure :-)


This comment has been minimized.

Copy link

@RobertRajcool RobertRajcool commented Nov 17, 2017

its really help us


This comment has been minimized.

Copy link

@pdbq21 pdbq21 commented Apr 18, 2018

It's help me, thanks


This comment has been minimized.

Copy link

@andonov85 andonov85 commented Jul 8, 2018

Perfection, its help a lot. I am with node-v57-linux-x64, Ubuntu 17.10 and Electron 2.0.4. Only to mention prepublish now is prepublishOnly and you need to install (for Ubuntu if "gyp ERR! stack Error: not found: make") -> "sudo apt-get install build-essential" before run "node-gyp rebuild". Thanks a lot! :)


This comment has been minimized.

Copy link

@cloverich cloverich commented Jul 25, 2018

In addition to the guide above, electron-rebuild will do this for you. I run it in my postinstall npm script, and manually any time I change my electron version.

Also the tl;dr of what's happening here: Packages like sqlite3 use compiled binaries, and these must be compiled for the environment where they are used. With Electron, its using a (potentially) different version of node than your locally installed node version, so you must compile sqlite3's binary for its environment.


This comment has been minimized.

Copy link

@fmacedoo fmacedoo commented Aug 9, 2019

Great! Worked nicely.

I would change --module_path=../lib/binding/node-[NODE-VER]-[PLATFORM]-[ARCH] to --module_path=../lib/binding/electron-[NODE-VER]-[PLATFORM]-[ARCH] to avoid the last MOVE step. But i didn't test that way.


This comment has been minimized.

Copy link

@DavidRiosAlex DavidRiosAlex commented Nov 28, 2019

this works!!!!! even in november 2019 ! ty so much you save me from days and days searching a solution ! I was going to install python-shell to use python scripts but no anymore, ty again.

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