1

我正在尝试在 vue-electron 项目中使用 bcrypt-package,但是当我尝试运行它时出现 N-api 版本问题:

Uncaught Error: The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.

我正在运行节点 12.16.1。

我阅读了有关 N-API 的文档,根据该版本矩阵,我不可能安装版本 1。但我找不到任何关于如何安装/配置/管理这些 N-API 版本的进一步文档。

我的 package.json:

{
  "version": "0.0.1",
  "license": null,
  "engines": {
    "node": "12.16.x"
  },
  "main": "./dist/electron/main.js",
  "scripts": {
    "build": "node .electron-vue/build.js && electron-builder",
    "build:dir": "node .electron-vue/build.js && electron-builder --dir",
    "build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
    "build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
    "dev": "node .electron-vue/dev-runner.js",
    "pack": "npm run pack:main && npm run pack:renderer",
    "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
    "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
    "postinstall": ""
  },
  "build": {
    "directories": {
      "output": "build"
    },
    "files": [
      "dist/electron/**/*"
    ],
    "dmg": {
      "contents": [
        {
          "x": 410,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        },
        {
          "x": 130,
          "y": 150,
          "type": "file"
        }
      ]
    },
    "mac": {
      "icon": "build/icons/icon.icns"
    },
    "win": {
      "icon": "build/icons/icon.ico"
    },
    "linux": {
      "icon": "build/icons"
    }
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.27",
    "@fortawesome/free-solid-svg-icons": "^5.12.1",
    "@fortawesome/vue-fontawesome": "^0.1.9",
    "axios": "^0.18.0",
    "bcrypt": "^4.0.1",
    "bootstrap": "^4.4.1",
    "bootstrap-vue": "^2.7.0",
    "dotenv": "^8.2.0",
    "dotenv-webpack": "^1.7.0",
    "mongoose": "^5.9.4",
    "mongoose-uuid2": "^2.3.0",
    "portal-vue": "^2.1.7",
    "uuid": "^7.0.2",
    "vue": "^2.5.16",
    "vue-electron": "^1.0.6",
    "vue-i18n": "^8.15.5",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "vuex-electron": "^1.0.0"
  },
  "devDependencies": {
    "ajv": "^6.5.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-minify-webpack-plugin": "^0.3.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "babel-register": "^6.26.0",
    "cfonts": "^2.1.2",
    "chalk": "^2.4.1",
    "copy-webpack-plugin": "^4.5.1",
    "cross-env": "^5.1.6",
    "css-loader": "^0.28.11",
    "del": "^3.0.0",
    "devtron": "^1.4.0",
    "electron": "^2.0.4",
    "electron-builder": "^20.19.2",
    "electron-debug": "^1.5.0",
    "electron-devtools-installer": "^2.2.4",
    "file-loader": "^1.1.11",
    "html-webpack-plugin": "^3.2.0",
    "mini-css-extract-plugin": "0.4.0",
    "multispinner": "^0.2.1",
    "node-loader": "^0.6.0",
    "style-loader": "^0.21.0",
    "url-loader": "^1.0.1",
    "vue-html-loader": "^1.2.4",
    "vue-loader": "^15.2.4",
    "vue-style-loader": "^4.1.0",
    "vue-template-compiler": "^2.5.16",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.4",
    "webpack-hot-middleware": "^2.22.2",
    "webpack-merge": "^4.1.3"
  }
}

完整的控制台堆栈跟踪:

Uncaught Error: The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.
at Object.module.exports.validate_package_json (/home/fabian/projects/prelude-pos/node_modules/node-pre-gyp/lib/util/napi.js:82:9)
at Object.validate_config (/home/fabian/projects/prelude-pos/node_modules/node-pre-gyp/lib/util/versioning.js:229:10)
at Object.exports.find (/home/fabian/projects/prelude-pos/node_modules/node-pre-gyp/lib/pre-binding.js:21:15)
at Object.<anonymous> (/home/fabian/projects/prelude-pos/node_modules/bcrypt/bcrypt.js:5:27)
at Object.<anonymous> (/home/fabian/projects/prelude-pos/node_modules/bcrypt/bcrypt.js:238:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at eval (webpack-internal:///bcrypt:1:18)
at Object.bcrypt (http://localhost:9080/renderer.js:2844:1)
at __webpack_require__ (http://localhost:9080/renderer.js:727:30)
at fn (http://localhost:9080/renderer.js:102:20)

到目前为止,我擦除并重新安装了 nodejs,清除了 node_modules 并重新安装了所有软件包,但没有区别。

4

1 回答 1

0

所以我最终找到了我自己问题的答案:

Electron 显然与它自己的 nodejs 版本捆绑在一起。更新电子修复了我的错误。

于 2020-05-01T19:14:28.977 回答