在 Windows 上为 Electron App 安装 npm sqlite3

Install npm sqlite3 on Windows for Electron App

我在 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 中配置得很好,但在这种情况下它不起作用,所以我尝试执行启动 electron-rebuild 的命令,选项 --代理:

"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" 的文件,但它不是,我不知道它应该在哪里,也不知道它必须做什么。

有帮助吗?

提前致谢。

因此,以下是使其发挥作用的步骤:

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

安装电子重建

npm install --save-dev electron-rebuild

使用 npm 安装 sqlite3

npm install --save sqlite3

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

"rebuild": "electron-rebuild -f -w sqlite3"

运行以下命令

npm run rebuild

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

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

被electron接受。