I have a native Node addon I wrote that I'm trying to add to an Electron app. I use npm install /path/to/addon
to install the addon. Then electron-rebuild
and electron-build
, which don't complain.
But when I run npm start
, in the dev console I get the following error:
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)
I can't find much online regarding this error. I've tried recompiling everything, tried rebuilding the addon with Electron as target and nothing helps. Why does this error happen, and how can I remedy it?
The error was with a silly one. In index.js, I was doing
let addon= require("node-gyp-build")("./");
Essentially,
"./"
will not link correctly when installed with npm since./
is the root directory of the current project not the installed. Using__dirname
instead will properly link the addonlet addon= require("node-gyp-build")(__dirname);
Note: I also switched to using prebuildify which means I no longer have to run npm electron-builder