SQLite 无法在 Windows 10 上与 Electron 和 Node 配合使用
我已经尝试了几个星期来安装 SQLite 并与 Electron 一起工作,但重建一直失败。
我在 Windows 10 上,这是我的步骤...
安装 Node... node-v12.16.3-x64
在安装 Node 期间,我选中了“自动安装必要工具”框
接下来,我为我的 Electron 项目创建一个全新的文件夹
然后我运行...
npm init -y
npm install --save electron
npm install --save sqlite3
npm install --save-dev electron-builder
所有这些都完成且没有错误。
然后我在脚本下将...添加到我的 package.json 中
“postinstall”:“electron-builder install-app-deps"
然后我运行
npm run postinstall
这会引发一堆错误,我陷入困境!
我祈祷有人能帮助我。
这是 postinstall 的输出:
> [email protected] postinstall D:\dropbox\CMPDB
> electron-builder install-app-deps
• electron-builder version=22.6.1
• rebuilding native dependencies [email protected] platform=win32 arch=x64
⨯ cannot execute cause=exit status 1
out=
> [email protected] install D:\dropbox\CMPDB\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
unpack_sqlite_dep
'C:\Users\Ion' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5): error MSB6006: "cmd.exe" exited with code 1. [D:\dropbox\CMPDB\node_modules\sqlite3\build\deps\action_before_build.vcxproj]
Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v9.0' (1)
errorOut=node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/electron-v9.0-win32-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (electron-v9.0 ABI, unknown) (falling back to source compile with node-gyp)
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:310:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Ion Hatzithomas\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallback-to-build" "--module=D:\\dropbox\\CMPDB\\node_modules\\sqlite3\\lib\\binding\\electron-v9.0-win32-x64\\node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=D:\\dropbox\\CMPDB\\node_modules\\sqlite3\\lib\\binding\\electron-v9.0-win32-x64" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=electron-v9.0"
gyp ERR! cwd D:\dropbox\CMPDB\node_modules\sqlite3
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64\node_sqlite3.node --module_name=node_sqlite3 --module_path=D:\dropbox\CMPDB\node_modules\sqlite3\lib\binding\electron-v9.0-win32-x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v9.0' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (D:\Dropbox\CMPDB\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:310:20)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
node-pre-gyp ERR! System Windows_NT 10.0.18362
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Dropbox\\CMPDB\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd D:\dropbox\CMPDB\node_modules\sqlite3
node-pre-gyp ERR! node -v v12.16.3
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ion Hatzithomas\AppData\Roaming\npm-cache\_logs\2020-05-25T01_12_42_765Z-debug.log
command='C:\Program Files\nodejs\node.exe' 'C:\Users\Ion Hatzithomas\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js' rebuild [email protected]
workingDir=
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `electron-builder install-app-deps`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ion Hatzithomas\AppData\Roaming\npm-cache\_logs\2020-05-25T01_12_42_818Z-debug.log
首先,我建议您检查您的 package.json 以查看您的依赖项中是否有 electron 以及以下依赖项:
"devDependencies": {
"electron": "^6.0.11",
"electron-builder": "^21.2.0",
"electron-rebuild": "^1.11.0"
}
如果即使有了这些依赖项也不起作用,请使用此命令将您的 electron 版本降级到 6.0.11 * npm i [email protected] * 并将 electron=builder 降级为与编写相同的版本。
之后,您需要在文件 main.js 中激活节点模块使用,如下所示:
win = new BrowserWindow(
{width: 800, height: 600,
webPreferences: {nodeIntegration:true}//New thing to add
}
) ;
然后以 npm run postinstall 结束
请确保以下事项 -
- 您拥有稳定的互联网连接
- 您已下载 nodejs 桌面开发所需的 Microsoft visual studio C++ 包
希望对您有所帮助...