ZeroMQ在electron-vue当中的简单应用

1,377 阅读1分钟

发布于 2021.02.19

把ZeroMQ集成到electron-vue 当中的一些坑

  • electron 版本问题

在官方文档中说明了使用ZMQ时的版本要求:

Node.js 10.2+ or Electron 3+ (requires a N-API version 3+) 而常用的electron-vue 库 github.com/SimulatedGR… 默认的electron 版本时2.0.1。 那么就需要升级electron 才能在electron-vue 的项目种使用。

npm install -D electron@3.0.1
  • zeromq rebuld 问题

在更新完electron 后依然可能出现一些问题,诸如:

Error: The module `...\node_modules\zeromq\build\Release\zmq.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 47. This version of Node.js requires
NODE_MODULE_VERSION 70. Please try re-compiling or re-installing

A dynamic link library (DLL) initialization routine failed" for "node_modules\zeromq\build\Release\zmq.node".

针对类似这种错误,需要做如下处理:

在/src/main/index.js 做如下修改:

  mainWindow = new BrowserWindow({
        height: 563,
        useContentSize: true,
        width: 1000,
        webPreferences: {
            nodeIntegration: true,
            webSecurity: false
        }
    })

在npm install zeromq@5 后运行

npm rebuild zeromq --runtime=electron --target=3.0.1

如此,zeromq 可以正常在electron项目中运行,最起码在我的里面可以。