node.js - 在 Windows 上为 Electron 应用程序安装 npm sqlite3

标签 node.js npm sqlite electron node-gyp

我在 Windows 中为 Electron 应用程序使用 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 执行启动 electro-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文件夹和package-lock.json 并按照以下步骤操作

安装 Electron 重建

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

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

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

被 Electron 接受。

关于node.js - 在 Windows 上为 Electron 应用程序安装 npm sqlite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52557538/

相关文章:

javascript - 如何使用 sequelize beforeCreate 自动生成 Id 值?

typescript - NPM 条件脚本(Windows/Mac)应执行不同的命令)

Android:SQLite - 查询 SelectionArgs 中的数组以及其他字符串值

java - 无法获取可写数据库。 SQLite 异常 : not an error (code 0)

java - 我将一轮高尔夫球的每洞得分存储在数据库中。我想编写一个函数,对表中的该列求和并显示在 toast 中

javascript - 等待 javascript 和 graphql/node 中的 Promise

javascript - 如何在node.js中使用console.log写入窗口的不同部分?

node.js - 使用强大的和(knox 或 aws-sdk)将文件上传到 Node.js 上的 S3

vue.js - 如何在没有 monorepo 的情况下在多个 vue 应用程序中组织代码(组件)共享

javascript - NodeJS - 为什么串行读取器失败?