【问题标题】:Problems compiling node.js version with Electron使用 Electron 编译 node.js 版本时出现问题
【发布时间】:2019-10-30 23:43:24
【问题描述】:

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

我已尝试采用另一个与 10.16.0 node.js 一起正常工作的 Electron 版本,但没有工作。

    "@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“错误”

【问题讨论】:

    标签: node.js electron nfc node-modules


    【解决方案1】:

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

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

    npm install --save-dev electron-rebuild
    

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

    $(npm bin)/electron-rebuild
    

    或者,如果您使用的是 Windows:

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

    您甚至可以在“脚本”部分创建一个别名为“重建”,您可以在需要时使用它。

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

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

    npm run rebuild
    

    希望这会有所帮助!

    【讨论】:

    • 当我这样做时出现此错误。\node_modules\.bin\electron-rebuild.cmd An unhandled error occurred inside electron-rebuild Los proyectos de esta soluci n se van a compilar de uno en uno. Para habilitar la compilaci n en paralelo, agregue el modificador "/m". addon.cpp pcsclite.cpp cardreader.cpp win_delay_load_hook.cc c:\users\terro\.electron-gyp\5.0.4\include\node\v8.h(4458): warning C4996: 'v8::WasmModuleObject::SerializedModule': se declar desusado (compilando archivo de origen ..\src\addon.cpp) [C:path\nfc\nfc-pcsc\node_modules\@pokusew\pcsclite\build\pcsclite.vcxproj]
    • 如果不清楚我想说什么,这是主要错误× Rebuild Failed An unhandled error occurred inside electron-rebuild
    • 您可以尝试在命令提示符中输入此命令吗? => set env GYP_MSVS_VERSION=2015 并重新运行 electron-rebuild ?
    • 现在我遇到了另一个问题An unhandled error occurred inside electron-rebuild gyp info it worked if it ends with ok
    • 好的。您能否一一尝试这些命令 => npm uninstall --save electron 完成后.. 发出此命令 => npm install --save electron@latest 然后尝试运行 electron-build 看看它是否有效。
    猜你喜欢
    • 1970-01-01
    • 2020-10-21
    • 2021-02-19
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多