package.json
"name": "billingapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"rebuild": "electron-rebuild -f -w billingapp"
},
"author": "S Kundu",
"license": "ISC",
"dependencies": {
"electron": "^1.7.11",
"sqlite3": "^3.1.13"
}
"devDependencies": {
"electron-rebuild": "^1.7.3"
}
index.js
const electron = require('electron');
const path = require('path');
const url = require('url');
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(path.join(__dirname, 'sample.db'));
const {app, BrowserWindow, Menu, ipcMain} = electron;
let mainWindow;
app.on('ready', function(){
// Create the login window
mainWindow = new BrowserWindow({
resizable: true,
fullscreen: false
});
// Load html in window
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'login.html'),
protocol: 'file:',
slashes: true
}));
});
login.html
<h1>Welcome to billing system</h1>
这些是代码文件。
安装NPM软件包的步骤
npm install electron
npm install sqlite3
当我移除贝娄代码时,它的工作非常完美:
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(path.join(__dirname, 'sample.db'));
但是使用这段代码,在运行时
npm start
正在获取贝娄错误:
应用程序在加载过程中抛出错误
错误:在module._resolveFileName(module.js:470:15)在function.module._resolveFileName(C:\users\sintu\desktoch\billingsystem\node_module\electronic\dist\resources\electronic.asar\common\reset-search-paths.js:35:12)在function.module._load(module.js:418:25)在module.require(module.js:498:17)在required((C:\users\sintu\desktop\billingsystem\node_modules\sqlite3\lib\sqlite3.js:4:15)对象。(C:\users\sintu\desktoes\billingsystem\node_module\sqlite3\lib\sqlite3.js:190:3)在module._compile(module.js:571:32)在object.module._extensions.js(module.js:580:10)在module.load(module.js:488:32)
当我运行npm run rebuild时,我得到了bellow错误
×重建失败
在electron-rebuild构建此解决方案中的项目时,出现了一个未处理的错误。要启用并行构建,请添加“/M”开关。C:\users\sintu\desktop\billingapp\node_modules\sqlite3\build\deps\action_before_build.vcxproj(20,3):错误MSB4019:找不到导入的项目“C:\microsoft.cpp.default.props”。确认声明中的路径是正确的,并且文件存在于磁盘上。gyp err!构建错误gyp错误!堆栈错误:C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
失败,退出代码:1 gyp ERR!在childprocess.onexit处堆栈(C:\users\sintu\desktop\billingapp\node_modules\node-gyp\lib\build.js:258:23)gyp错误!在emitTwo(events.js:126:13)处堆栈gyp错误!在childprocess.emit(events.js:214:7)处堆栈gyp错误!在process.childprocess._handle.onexit处堆栈(internal/child_process.js:198:12)gyp错误!系统Windows_NT 6.1.7601 gyp错误!命令“C:\Program Files\nodejs\node.exe”“C:\users\sintu\desktop\billingapp\node_modules\node-gyp\bin\node-gyp.js”“rebuild”“--target=1.7.11”“--arch=x64”“--dist-url=https://atom.io/download/electronic”“--build-from-source”“--module_name=node_sqlite3”“cwd C:\users\sintu\desktop\billingapp\node_modules\sqlite3 gyp err!node-v v8.9.1 gyp err!node-gyp-v v3.6.2 gyp错误!不确定
失败,退出代码:%1
错误:在此解决方案中一次生成一个项目。要启用并行构建,请添加“/M”开关。C:\users\sintu\desktop\billingapp\node_modules\sqlite3\build\deps\action_before_build.vcxproj(20,3):错误MSB4019:找不到导入的项目“C:\microsoft.cpp.default.props”。确认声明中的路径是正确的,并且文件存在于磁盘上。gyp err!构建错误gyp错误!堆栈错误:C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
失败,退出代码:1 gyp ERR!在childprocess.onexit处堆栈(C:\users\sintu\desktop\billingapp\node_modules\node-gyp\lib\build.js:258:23)gyp错误!在emitTwo(events.js:126:13)处堆栈gyp错误!在childprocess.emit(events.js:214:7)处堆栈gyp错误!在process.childprocess._handle.onexit处堆栈(internal/child_process.js:198:12)gyp错误!系统Windows_NT 6.1.7601 gyp错误!命令“C:\Program Files\nodejs\node.exe”“C:\users\sintu\desktop\billingapp\node_modules\node-gyp\bin\node-gyp.js”“rebuild”“--target=1.7.11”“--arch=x64”“--dist-url=https://atom.io/download/electronic”“--build-from-source”“--module_name=node_sqlite3”“cwd C:\users\sintu\desktop\billingapp\node_modules\sqlite3 gyp err!node-v v8.9.1 gyp err!node-gyp-v v3.6.2 gyp错误!不确定
失败,退出代码:1位于SafeSubscriber._ERROR(C:\users\sintu\desktop\billingapp\node_modules\spawn-rx\lib\src\index.js:277:84)位于SafeSubscriber.__tryorunsub(C:\users\sintu\desktop\billingapp\node_modules\rxjs\subscriber.239:16)位于SafeSubscriber.ERROR(C:\users\sintu\desktopSktop\billingapp\node_modules\rxjs\subscriber.js:186:22)npm err!code ELIFECYCLE npm err!errno 4294967295 npm err!billingapp@1.0.0 rebuild:electron-rebuild-f-w billingapp
npm err!退出状态4294967295 npm err!npm err!billingapp@1.0.0 rebuild脚本失败。npm err!这可能不是npm的问题。上面可能有其他日志记录输出。
npm错误!此运行的完整日志可以在:npm err!C:\users\sintu\appdata\roaming\npm-cache_logs\2018-01-30t15_36_46_678z-debug.log
您的脚本似乎有很多问题,但SQLite也遇到了一个罕见的问题。
0)您可以在这里找到我的Github源代码,该源代码一直在运行,直到出现此错误:
Cannot read property 'on' of undefined
但那是另一个问题:D
1)您的package.json格式不正确(例如,没有启动脚本)
新建package.json
{ // there was no begining bracket
"name": "billingapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"rebuild": "electron-rebuild -f -w billingapp",
"start": "node index.js" // new start script
},
"author": "S Kundu",
"license": "ISC",
"dependencies": {
"electron": "^1.7.11",
"sqlite3": "^3.1.0" // I used this version
},
"devDependencies": {
"electron-rebuild": "^1.7.3"
}
}
2)当我安装sqlite时,遇到了这个问题https://github.com/mapbox/node-sqlite3/issues/758
sqlite3似乎不能与nodejs的最后一个版本一起使用,因此您需要安装Node@8.9.3您可以使用nvm来实现:
请参阅关于sqlite3问题的注释
treedbox于2017年12月20日发表评论