电子应用程序找不到 sqlite3 模块

2022-01-10 00:00:00 node.js electron sqlite npm

在我的电子应用中,我通过 npm 安装了 sqlite3

In my electron app I have installed sqlite3 via npm

npm install sqlite3

但是一旦我尝试与数据库交互,它就找不到数据库,这是日志:

But once i try to interact with the database it cant find the database, here is the log:

未捕获的错误:找不到模块 'D:playelectron-quick-start ode_modulessqlite3libindingelectron-v1.3-win32-x64 ode_sqlite3.node'

Uncaught Error: Cannot find module 'D:playelectron-quick-start ode_modulessqlite3libindingelectron-v1.3-win32-x64 ode_sqlite3.node'

这里是JS代码:

console.log('whooooo');

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

db.serialize(function () {
    db.run("CREATE TABLE lorem (info TEXT)");   

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

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

我也是这样尝试的:

npm install sqlite3 --build-from-source

但安装失败!

另外,我正在使用 Python3.你如何安装一个模块来使用电子?

Also, i am using Python3. How do you install a module to work with electron?

推荐答案

首先:

npm install electron-rebuild

然后多试几次:

./node_modules/.bin/electron-rebuild -w sqlite3 -p

相关文章