【问题标题】:How to compile my Electron code for Windows on a Mac including native sqlite3 module?如何在包括本机 sqlite3 模块的 Mac 上为 Windows 编译我的 Electron 代码?
【发布时间】:2019-09-30 20:28:01
【问题描述】:

我的目标是创建一个适用于 Mac 的发行版和另一个适用于 Windows 的发行版。我想从我的 Mac 创建这两个发行版。目前,我的 Mac 发行版运行良好。

但是我仍然对 Windows 发行版的 sqlite3 模块有问题。

我的应用使用的唯一原生模块是 sqlite3。

我真的不知道该怎么做才能最终让我的应用在 Windows 上正常运行。我不想在 Windows 机器上编译我的代码。我只想在我的 Mac 上编译我的代码。

我的配置是:

  • 节点 v12.2.0
  • npm v6.9.0
  • 电子 v5.0.1
  • sqlite3 v4.0.8
  • MacOS Mojave v10.14.0

尝试为 Windows 编译 sqlite3 模块:

node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=win32 --target_arch=x64 --target=12.2.0

node-pre-gyp 返回这些消息:

node-pre-gyp WARN Using request for node-pre-gyp https download
Warning: node-pre-gyp could not find exact match for 12.2.0
Warning: but node-pre-gyp successfully choose 12.0.0 as ABI compatible target
Warning: node-pre-gyp could not find exact match for 12.2.0
Warning: but node-pre-gyp successfully choose 12.0.0 as ABI compatible target

[sqlite3] Success: "/Users/Flooder/Programmes/electron/c4/node_modules/sqlite3/lib/binding/node-v72-win32-x64/node_sqlite3.node" is installed via remote

我得到一个新目录:./node_modules/sqlite3/lib/binding/node-v72-win32-x64

我重命名这个新目录:./node_modules/sqlite3/lib/binding/electron-v5.0-win32-x64

当我在 Windows 机器上尝试我的新发行版时,我收到了这个错误:

未捕获的异常: 错误:模块 D:\c4\resources\app\node_modules\sqlite3\lib\binding\electron-v5.0-win32-x64\node_sqlite3.node 是使用 NODE_MODULE 72 针对不同的 Node.js 版本编译的。这个版本的Node.js 需要 NODE_MODULE_VERSION 70。请尝试重新编译或重新安装模块(例如,使用 'npm rebuild' 或 'npm install')。

...

我被这个问题困扰了好几个星期了......

真的可以在 Mac 上为 Windows 编译 sqlite3 模块吗?

node-pre-gyp 是解决这个问题的正确方法吗?怎么样?

【问题讨论】:

  • 我遇到了与node-canvas 类似的问题——(“NODE_MODULE_VERSION”不匹配等)。花了几天时间折腾所有的版本,但最终放弃了。
  • 朋友,我也快放弃了!

标签: electron node-sqlite3 node-pre-gyp


【解决方案1】:

最后,这是我的解决方案:

  • 在我的 Mac 上安装了 Parallel Desktop;
  • 在此虚拟机中安装了 Windows 10;
  • 在Windows虚拟机上安装node、npm、python、electron、electron-rebuild、sqlite等;
  • 在虚拟机上使用“electron-rebuild -f -w sqlite3”重新编译 sqlite3
  • 将新的 ./node_modules/sqlite3/lib/binding/electron-v5.0-win32-x64 从 Windows 复制到 Mac
  • 在 mac 上,使用 electron-packager 为 PC 重新编译了我的电子应用程序

现在,Windows 的新编译版本可以在 Win 机器上运行!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-07
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多