使用 Electron 编译 node.js 版本时出现问题

Problems compiling node.js version with Electron

我正在尝试 运行 10.16.0 节点 js 版本的电子项目,但出现错误。 我正在使用这个库 https://github.com/pokusew/nfc-pcsc

我尝试使用另一个 Electron 版本,它可以在 10.16.0 node.js 上正常工作,但没有成功。

    "@pokusew/pcsclite": "^0.5.2",
    "electron-version": "^2.0.1"
  },
  "devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.5",
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "@babel/plugin-syntax-object-rest-spread": "^7.2.0",
    "@babel/plugin-transform-modules-commonjs": "^7.4.4",
    "@babel/register": "^7.4.4",
    "ava": "^2.0.0",
    "chalk": "^2.4.2",
    "cross-env": "^5.2.0",
    "electron": "^5.0.4",
    "mock-require": "^3.0.3",
    "triple-beam": "^1.3.0",
    "winston": "^3.2.1"
  }

https://i.imgur.com/UhSjlo6.png "error"

您需要包含 electron-rebuild 包,它根据您的 Electron 项目正在使用的 Node.js 版本重建本机 Node.js 模块。这允许您在 Electron 应用程序中使用本机 Node.js 模块,而无需您的系统版本 Node.js 完全匹配。

您可以使用以下命令安装此包,

npm install --save-dev electron-rebuild

然后,每当您安装新的 npm 包时,重新运行 electron-rebuild:

$(npm bin)/electron-rebuild

或者如果您在 Windows:

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

您甚至可以在 "scripts" 部分中创建一个别名 "rebuild",您可以在需要时随时使用它。

"scripts": {
  "rebuild": "electron-rebuild -f -w yourmodule"
}

添加以上内容后,您可以使用以下命令,

npm run rebuild

希望对您有所帮助!