I am getting an error while connecting to sqlite3 database

徘徊边缘 提交于 2019-12-25 04:07:21

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/41307807/i-am-getting-an-error-while-connecting-to-sqlite3-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!