Can not load native module in production
See original GitHub issue- 19.56.2:
- ia32:
Hi,
I want to use a custom native addon module in my electron app. The module is located in
C:\my-application-root-dir\node_modules\myaddon\build\Release\myaddon.node
and in src\main\index.js I require my module with relative path:
var myaddon = require('../../node_modules/myaddon/build/Release/myaddon')
in the package.json, I put my module in dependencies:
"dependencies": {
"myaddon":"^1.0.0",
},
this config is working in the develop environment.
When I build my app with electron-builder for production, build was successfully and a setup file is generated, and I find the myaddon in unpacked directory under build
C:\my-application-root-dir\build\win-ia32-unpacked\resources\app.asar.unpacked\node_modules\myaddon\build\Release\myaddon.node
However after I install the application in another PC, A Javascript error occurred in the main process:
Cannot open C:\my-application-root-dir\node_modules\myaddon\build\Release\myaddon.node: Error: Uncaught Exception:
Error: Cannot find module .
After I search for answers for hours I found something in the document:
If you have native addons of your own that are part of the application (not as a dependency), set nodeGypRebuild to true.
does this mean, in my case, myaddon is not as a dependency? Should I put my myaddon inside /node_modules or in /src ?
And if I set nodeGypRebuild to true, the build process will fail, did I make something wrong?
Or the way I require my custom addon is wrong?
Any help would be appreciated.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top GitHub Comments
It seems that node-loader use a hardcore absolute path: https://github.com/webpack-contrib/node-loader/issues/12
issue solve by replace node-loader with native-ext-loader, I also test node-addon-loader, but it’s not working.
webpack.main.config.js:
i am also unable to load native dll using ffi