Make Electron Work with Sqlite3

The other day I tried to integrate knex with a SQLITE3 back-end. Unfortunately, the instant I’ve tried to instantiate knex, I’ve got a lot of errors. After getting rid of them, I found that I can’t get sqlite3 to work at all, even though I’ve checked the installation and it was OK (got the binary downloaded and even rebuilt it).

Uncaught Error: Cannot find module ‘/…/node_modules/sqlite3/lib/binding/node-v51-darwin-x64/node_sqlite3.node’

So, here are the steps that I did to make it work:

  1. install electron-rebuild

  2. install sqlite3 using npm

  3. rebuild electron with sqlite3. In package.json scripts section, add:

  4. run the following command

Now, you’ll get another binding, something like:

which is accepted by electron.


A little experiment: If you find this post and ad below useful, please check the ad out :-)

26 thoughts on “Make Electron Work with Sqlite3

  1. After npm run rebuild the binding that is created for me is


    So when I run npm start I receive an error:

    $ npm install sqlite3 --save
    Error: Cannot find module '../app/node_modules/sqlite3/lib/binding/electron-v1.4-darwin-x64/node_sqlite3.node'

      1. Thanks for the quick response! The scripts and dependencies section of the json looks like this:

        "scripts": {
        "start": "electron ./ --enable-logging",
        "dev": "NODE_ENV='development' npm run start",
        "dist": "build -mwl --x64 --ia32",
        "build-electron": "ng build && cp src/electron/* dist/",
        "electron": "npm run build-electron && electron dist/",
        "electron-dist": "electron dist/",
        "postinstall": "install-app-deps",
        "release": "build",
        "rebuild": "electron-rebuild -f -w sqlite3"

        "dependencies": {
        "bookshelf": "^0.10.3",
        "d3": "^4.7.4",
        "jquery": "^3.2.1",
        "knex": "^0.13.0",
        "request": "^2.81.0",
        "sequelize": "^3.7.1",
        "sqlite3": "^3.1.8",
        "topojson": "^3.0.0"

          1. Hi Laur, are you referring to:

            "devDependencies": {
            "electron": "^1.6.2",
            "electron-builder": "^17.1.1",
            "electron-packager": "^8.6.0",
            "electron-prebuilt": "^1.4.13",
            "electron-rebuild": "^1.5.7"


          2. Hmm. I think you have interference from electron-prebuilt. I’m using almost the same versions of the others (my electron version is 1.6.6) on my system and I’m not getting any errors like that.

  2. I couldn’t get anything work with this and the previous tutorial. The build just hangs.

    Could you provide a bit of context for the tips you give? I have no idea why i need to add the config you advice into webpack.conf.

  3. With these instructions i’m getting:

    $ cross-env NODE_ENV=production electron ./app/
    Knex: run
    $ npm install sqlite3 –save
    Error: Cannot find module “node-pre-gyp”
    at /path/to/app/

  4. and also this:

    [0] WARNING in ./~/sqlite3/lib/sqlite3.js
    [0] 4:14-35 Critical dependency: the request of a dependency is an expression
    [0] npm run build-main exited with code 0
    $ cross-env NODE_ENV=production electron ./app/
    Knex: run
    $ npm install sqlite3 –save
    Error: Cannot find module “node-pre-gyp”
    at /path/to/app/

  5. got a bit forward (i had typoed the externals -part), but now i get following error:

    [1] npm run build-renderer exited with code 0
    $ cross-env NODE_ENV=production electron ./app/
    Knex: run
    $ npm install sqlite3 –save
    Error: Cannot find module ‘/path/to/app/node_modules/sqlite3/lib/binding/electron-v1.6-darwin-x64/node_sqlite3.node’
    at Module._resolveFilename (module.js:470:15)

    1. Can you paste the relevant sections from your package.json (dependencies, devDependencies and scripts) ?

  6. Hi, I did all steps mentioned but when i ran the last command “npm run rebuild”, i am getting this:
    constructor(lifecycle, buildPath, electronVersion, arch = process.arch, extraModules = [], forceRebuild = false, headerURL = ‘’, types = [‘prod’, ‘optional’], mode = defaultMode) {

    SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object. (C:\electron\sqlite\node_modules\electron-rebuild\lib\src\cli.js:16:19)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

  7. i got this result

    Error: Cannot find module ‘/Users/lzy/Desktop/data/node_modules/sqlite3/lib/binding/electron-v1.6-darwin-x64/node_sqlite3.node’

    1. Anyone with this problem whould try to change the script to “rebuild”: “electron-rebuild -f -w sqlite3 -v 1.6” or the version specified in the error. Worked for me

  8. In order to make it working I had to remove complete node_modules folder and first go with npm install then I followed all steps and everything is working as it should.

    Thank you!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top