electron 使用NODE_MODULE_VERSION针对不同的Node.js版本进行编译

2skhul33  于 2022-12-08  发布在  Electron
关注(0)|答案(1)|浏览(519)

节点版本:v12.22.11
电子版:^11.1.0版本
RobotJS版本:^0.6.0版本
执行项目时将提示以下错误消息。

App threw an error during load
Error: The module '\\?\\node_modules\robotjs\build\Release\robotjs.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 85. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1812)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (\node_modules\robotjs\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)

我试过执行npm rebuildnpm install,但这并不能解决我的问题。

20221029-已更新

这是我的全部。json

{
  "name": "robotjs-proj",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "postinstall": "electron-builder install-app-deps && node_modules/.bin/electron-rebuild --module-dir .",
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "^11.1.0",
    "electron-builder": "^23.6.0",
    "mathjs": "^8.1.0",
    "robotjs": "^0.6.0",
    "robotjs-node12": "^0.5.3"
  },
  "devDependencies": {
    "@types/node": "^18.11.7",
    "electron-rebuild": "^2.3.4"
  }
}
yizd12fk

yizd12fk1#

将postinstall脚本插入到package.json中

...
"start": .......,
"preinstall": .....,
"postinstall": "electron-builder install-app-deps && node_modules/.bin/electron-rebuild --module-dir .",
"dist": ....,
...

相关问题