在Windows上为Electron App安装npm sqlite3

时间:2018-09-28 14:31:45

标签: node.js npm sqlite electron node-gyp

我在Windows上为电子应用程序在npm中安装sqlite3时遇到问题。 我用npm安装了sqlite3:

npm i sqlite3

然后我执行了:

.\node_modules\.bin\electron-rebuild.cmd

我有这个错误:

× Rebuild Failed

An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@8.12.0 | win32 | x64
gyp http GET https://atom.io/download/electron/v2.0.10/iojs-v2.0.10.tar.gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: getaddrinfo EAI_AGAIN atom.io:443
gyp ERR! stack     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\WindowsDev\\CopyWatcher\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=2.0.10" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=node_sqlite3" "--module_path=D:\\WindowsDev\\CopyWatcher\\node_modules\\sqlite3\\lib\\binding\\electron-v2.0-win32-x64" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.0.2/{toolset}/" "--package_name=electron-v2.0-win32-x64.tar.gz"
gyp ERR! cwd D:\WindowsDev\CopyWatcher\node_modules\sqlite3
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

一切似乎都表明它是代理,我在.npmrc中对其进行了很好的配置,但是在这种情况下它不起作用,因此我尝试使用选项--proxy执行启动电子重建的命令:

"C:\\Program Files\\nodejs\\node.exe" "D:\\WindowsDev\\CopyWatcher\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=2.0.10" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=node_sqlite3" "--module_path=D:\\WindowsDev\\CopyWatcher\\node_modules\\sqlite3\\lib\\binding\\electron-v2.0-win32-x64" "--proxy=http://127.0.0.1:3131/" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.0.2/{toolset}/" "--package_name=electron-v2.0-win32-x64.tar.gz"

但是我有这个错误:

gyp: binding.gyp not found (cwd: D:\WindowsDev\CopyWatcher) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (D:\WindowsDev\CopyWatcher\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\WindowsDev\\CopyWatcher\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=2.0.10" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=node_sqlite3" "--module_path=D:\\\\WindowsDev\\\\CopyWatcher\\\\node_modules\\\\sqlite3\\\\lib\\\\binding\\\\electron-v2.0-win32-x64" "--proxy=http://127.0.0.1:3131/" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.0.2/{toolset}/" "--package_name=electron-v2.0-win32-x64.tar.gz"

似乎它正在寻找一个名为“ binding.gyp”的文件,但实际上并非如此,我不知道它应该在哪里或必须做什么。

有帮助吗?

谢谢。

1 个答案:

答案 0 :(得分:4)

因此,以下是使其工作的步骤:

首先删除您的node_modules文件夹和package-lock.json 并按照以下步骤

安装电子重建

  

npm install --save-dev electronic-rebuild

使用npm安装sqlite3

  

npm install-保存sqlite3

用sqlite3重建电子。在package.json脚本部分中,添加:

  

“重建”:“电子重建-f -w sqlite3”

运行以下命令

  

npm运行重建

现在,您将获得另一个绑定,例如:

  

/.../ node_modules / sqlite3 / lib / binding / electron-v1.4-darwin-x64 / node_sqlite3.node

被电子接受的