Local native Node module causes error: Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=75 uv=1 libc=glibc

Local native Node module causes error: Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=75 uv=1 libc=glibc

我有一个我写的本机 Node 插件,我正在尝试将其添加到 Electron 应用程序中。我使用 npm install /path/to/addon 安装插件。然后是 electron-rebuildelectron-build,它们不抱怨。

但是当我 运行 npm start 时,在开发控制台中出现以下错误:

Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=75 uv=1 libc=glibc
    at Function.load.path (C:\path\to\node_modules\node-gyp-build\index.js:55:9)
    at load (C:\path\to\node_modules\node-gyp-build\index.js:20:30)
    at Object.<anonymous> (C:\path\to\index.js:2:42)
    at Object.<anonymous> (C:\path\to\index.js:27:3)
    at Module._compile (internal/modules/cjs/loader.js:880:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:892:10)
    at Module.load (internal/modules/cjs/loader.js:735:32)
    at Module._load (internal/modules/cjs/loader.js:648:12)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)

关于这个错误,我在网上找不到太多信息。我已经尝试重新编译所有内容,尝试以 Electron 作为目标重建插件,但没有任何帮助。为什么会出现这个错误,我该如何补救?

错误是一个愚蠢的错误。 在index.js,我在做

let addon= require("node-gyp-build")("./");

本质上,"./" 在使用 npm 安装时不会 link 正确,因为 ./ 是当前项目的根目录,而不是安装的。使用 __dirname 将正确地 link 插件

let addon= require("node-gyp-build")(__dirname);

注意:我也切换到使用 prebuildify 这意味着我不再需要 运行 npm electron-builder