我想使用电子开发桌面应用程序,该电子程序使用通过命令通过npm安装的sqlite3软件包
npm install --save sqlite3
但它在电子浏览器控制台中出现以下错误
Uncaught Error: Cannot find module 'E:\allcode\eapp\node_modules\sqlite3\lib\binding\node-v45-win32-x64\node_sqlite3.node'
我的开发环境是Windows 8.1 x64节点版本12.7
我的package.json文件如下所示:
{
"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文件
var app = require('app');
var BrowserWindow = require('browser-window');
require('crash-reporter').start();
var mainWindow = null;
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
});
});
my.js文件
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('mydb.db');
db.serialize(function() {
db.run("CREATE TABLE if not exists 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();
index.html文件
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div >
<div>
<h2>Hello</h2>
</div>
</div>
<!--<script src="js/jquery-1.11.3.min.js"></script>-->
<script src="js/my.js"></script>
</body>
</html>
npm install