How to use sqlite3 module with electron?

electron angular sqlite
electron-forge sqlite
npm sqlite3
ngx-electron example
electron sqlite react
electron native modules
electron database

I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command

npm install --save sqlite3

but it gives the following error in electron browser console

Uncaught Error: Cannot find module 'E:\allcode\eapp\node_modules\sqlite3\lib\binding\node-v45-win32-x64\node_sqlite3.node'

My development environment is windows 8.1 x64 node version 12.7

my package.json file looks like this:

  "name": "eapp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron-prebuilt": "^0.32.1"
  "dependencies": {
    "angular": "^1.3.5",   
    "sqlite3": "^3.1.0"

index.js file

var app = require('app');
var BrowserWindow = require('browser-window'); 
var mainWindow = null;

app.on('window-all-closed', function() {  
    if (process.platform != 'darwin') {

app.on('ready', function() {
    // Create the browser window.
    mainWindow = new BrowserWindow({width: 800, height: 600}); 
    mainWindow.loadUrl('file://' + __dirname + '/index.html');   
    mainWindow.on('closed', function() {       
        mainWindow = null;

my.js file

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('mydb.db');

db.serialize(function() {"CREATE TABLE if not exists lorem (info TEXT)");

    var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
    for (var i = 0; i < 10; i++) {"Ipsum " + i);

    db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
        console.log( + ": " +;


index.html file

<!DOCTYPE html>
<head lang="en">
    <meta charset="UTF-8">
<div >

<!--<script src="js/jquery-1.11.3.min.js"></script>-->
<script src="js/my.js"></script>

By far the easiest way to use SQLite with electron is with electron-builder.

First, add a postinstall step in your package.json:

"scripts": {
   "postinstall": "install-app-deps"

and then install the necessary dependencies and build:

npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall

electron-builder will build the native module for your platform, with the correct name for the Electron binding; and you can then require it in code as normal.

See my github repo and blog post - it took me quite a while to figure this out too.

node.js - How to use sqlite3 module with electron?, By far the easiest way to use SQLite with electron is with electron-builder . First, add a postinstall step in your package.json: "scripts": { "postinstall":  In this tutorial, we'll see how to use SQLite 3 with Electron. We'll specifically look at how to setup SQLIte 3 to work with Electron in a Windows development environment. Installing Electron is straightforward and easy but unfortunately that's not the case for SQLite 3 as it requires compiling to target the Electron ABI for Windows.

I would not recommend the native node sqlite3 module. It requires being rebuild to work with electron. This is a massive pain to do - At least I can never get it to work and their a no instructions to for rebuilding modules on windows.

Instead have a look at kripken's 'sql.js' module which is sqlite3 that has been compiled 100% in JavaScript.

Installing and rebuilding Sqlite3 for use with Electron, Having trouble with a native dependency? Getting a "module not found" on native modules Duration: 4:45 Posted: Jan 3, 2019 The take away from this blog article is that when you are developing using Electron and SQLite on Windows, you will need to have the SQLite native module built for that. You can use the electron-rebuild package to do that but you still need to have additional prerequisite for this to work. Those are Python 2.7 and MS Build Tools V140.

How to use sqlite3 module with electron? - electron, I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command npm install --save sqlite3 but it  The Electron backend will handle and process messages sent from the front and manage the sqlite3 database. We will be using sqlite3 for our database and need to install it. $ npm install sqlite3 --save. A hurdle I ran into while working with sqlite3 and Electron initially, was that sqlite’s native binaries need to be recompiled for use with Electron.

I was having same problem. Tried everything and atlast this worked for me :-

npm install --save sqlite3
npm install --save electron-rebuild
npm install --save electron-prebuilt

This will create "electron-v1.3-win32-x64" folder in .\node_modules\sqlite3\lib\binding\ location which is used by electron to use sqlite3.

Just start application and you will be able to use sqlite3 now.

Electron SQLite3 Integration · GitHub, When trying to use the node-sqlite3 module in Electron I got the error: Error: Cannot find Using Ubuntu 16.04 with Node 7.1.0 and Electron 1.4.12. I read the  Hi How to install any Sqlite on Electron? I will install node-gyp and node-pre-gyp and sqlite3 and python 3 6 but when I require sqlite3 module its say: Cannot find module 'C: ode\e2 ode_modules\sqlite3\lib\binding\electron-v1.6-win32-

A simpler solution:

  1. Install electron-rebuild npm i electron-rebuild --save-dev
  2. Launch electron-rebuild ./node_modules/.bin/electron-rebuild (or .\node_modules\.bin\electron-rebuild.cmd on windows)
  3. Go to "node_modules/sqlite3/lib/binding/" and rename the folder "electron-v0.36-darwin-x64" to "node-v47-darwin-x64"

PS: v47 is my version, be careful to choose the good one (in your case v45)

electron-sqlite3, Usage. Note: the module must be installed before use. var sqlite3 = require('​sqlite3').verbose();. var db = new sqlite3.Database(':memory:');. Gist notes. How I got SQLCipher working with Electron on macOS: First compile SQLCipher and dynamically link it to macOS' crypto libraries. Don't use OpenSSL.

sqlite3, Asynchronous, non-blocking SQLite3 bindings. Electron v1.3.X, v1.6.x, Usage. Note: the module must be installed before use. var sqlite3  Run Command npm i --save-dev electron-rebuild from your project directory.After Installing the ˚ electron-rebuild. Ru the following command to build sqlite3 binary for your platform../node_modules/.bin/electron-rebuild -w sqlite3 -p If rebuild fails, run npm install and then run the above-given command once again.

How to use sqlite3 module with electron?, I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command npm install --save sqlite3. Electron Help Thread. This thread is for anyone who needs help using Electron with better-sqlite3. better-sqlite3 is a Node.js package, not an Electron package. If third parties like Electron decide to do fancy things that happen to break a perfectly functioning Node.js package, it is not an issue with that package.

Setting Up SQLite with Electron on Windows, This is because SQLite is a native Node module and it has not been built for Electron targeting the platform I am using. If this was a plain Node  Search less. Build more. Use Stack Overflow for Teams at work to share knowledge with your colleagues. Free 30 day trial. Start your trial.

  • Using your electron-boilerplate-sqlite is indeed the easier method, but with npm install
  • when run 'npm run postinstall', i got this error "Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch."
  • This has saved my hide not once, but twice so far!
  • Does anyone know whether the --save sqlite3 option can be reliably tagged onto the first line (with --save-dev electron-builder), where npm install would only be run once?
  • This does not work for me, I get errors like ` ../../nan/nan_object_wrap.h:67:18: error: ‘class Nan::Persistent<v8::Object>’ has no member named ‘MarkIndependent’`
  • Electron docs are pretty clear that in order to use bundled native modules, you are required to rebuild them in order to work with electron. Either use the electron-rebuild utility which works most of the time or manually set the gyp flags:
  • Sorry for the slow response. is a handy tool for rebuilding in development.… describes a multi-platform build strategy for production builds. Jut remember, once you introduce native deps, you lose the ability to cross compile for different OSs. has decent docs on necessary windows compiler tools.
  • none of these comments are relevant to this answer!
  • It should be mentioned that sql.js can not operate on the filesystem. Everytime you need to change the database you have to write the whole thing to disk. Making it pretty much useless for most scenarios.
  • sql.js its more like a toy, made for fun. It cannot be better than NeDB and other nosql databases, because its store all database in memory. So there is no good reason to use it. For small database use nosql like NeDB, for larger you have to compile sqlite
  • In Nodewebkit, I must compile the sqlite. Same rule apply for the electron?
  • @Wexoni AFAIK every node module with native bindings must be compiled against electron headers.
  • Forgive my ignorance, but the way I understand it... same rule apply for Electron and for NW?