0

I am getting an error while connecting to sqlite3 database.

This is my code

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

db.serialize(function(){

    dbb.run("create table user (id int, db text)");
    var stmt = db.prepare("insert into user values(?,?)");
    for(var i=0; i<10; i++){

        var d = new Date();
        var n = d.toLocateTimeString();
        stmt.run(i,n);

    }   
    stmt.finalize();

    db.each("select id, dt from user",function(err,row){
        console.log("user id:"+row.id,row.dt);
    });
});
db.close();

Error is:

Uncaught Error: Cannot find module 'path_to_project\node_modules\sqlite3\lib\binding\electron-v1.4-win32-ia32\node_sqlite3.node'

When i check in this folder node_modules\sqlite3\lib\binding, it's having a folder and a file like node-v48-win32-ia32\node_sqlite3.node instead of electron-v1.4-win32-ia32\node_sqlite3.node.

Somebody suggested me to change the folder name node-v48-win32-ia32 to electron-v1.4-win32-ia32. Then it will work. But it returns another error

ELECTRON_ASAR.js:173 Uncaught Error: The system cannot find message text for message number 0x%1 in the message file for %2. \?\path_to_project\node_modules\sqlite3\lib\binding\electron-v1.4-win32-ia32\node_sqlite3.node

Can anyone suggest a solution for this? I searched a lot, but no solution found for this one.

Mehdi Dehghani
  • 10,970
  • 6
  • 59
  • 64
Jay
  • 673
  • 3
  • 7
  • 21

2 Answers2

3

I got this working by using electron-rebuild

First install:

npm install --save-dev electron-rebuild npm install --save-dev electron-prebuilt

Then, in your package.json add the script:

"rebuild": "electron-rebuild -f -w sqlite3 -v 1.X"

and run

npm run rebuild

I had to run it several times, changing the -v to the version needed, 1.2, 1.4 or 1.6

Victor Ivens
  • 2,221
  • 2
  • 22
  • 32
1

Just like Victor Ivens said above,

npm install --save-dev electron-rebuild

Then, in your package.json add the script:

"rebuild": "electron-rebuild -f -w sqlite3 -v 1.7" // for version 1.7

and voila, it works. You can ignore prebuilt

Suraj
  • 96
  • 1
  • 2
  • 13