node-loader "Specified module could not be found" when running packaged or build project on a different computer.
- Operating System: Windows 10
- Node Version: v14.15.1
- NPM Version: 6.14.8
- webpack Version: Using @electron-forge/plugin-webpack v6.0.0-beta.57"
- node-loader Version: v2.0.0
I have a basic electron project with cpp addons, build using the electron-forge -webpack template. When I packaging the project into an exe. It is working on the system the exe was generated but when copying and testing on another computer it is showing error that the .node file is not found by node-loader

I tried to run "electron-forge make" and run the installer and then tested the app, same error was comming.

Whereas the .node file is located in the same location

I am calling the node module in my main.js file using the bindings library and I am also using node-bindings-loader to manage the bindings path.
const addon = require("bindings")("libsdr.node");
My package.json file
"main": ".webpack/main",
"gypfile": "true",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"clean": "rimraf 11.1.0 out build bin dist .webpack",
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": {
"name": "Robosushie",
"email": "[email protected]"
},
"license": "MIT",
"config": {
"forge": {
"packagerConfig": {
"arch": "x64",
"asar": {
"unpack": "*.node"
}
},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "boxrf_v3.0.0"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
],
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
"html": "./src/index.html",
"js": "./src/renderer.js",
"name": "main_window"
}
]
}
}
]
]
}
},
My webpack.main.config.js
target: "electron-main",
node: {
__dirname: false,
},
entry: "./src/main.js",
module: {
rules: [
{
test: /\.node$/,
use: "node-loader",
},
{
test: /\.js$/,
loader: "node-bindings-loader",
},
Any help would be appreciated. I have also tried may other combinations with other node loaders also but none of them worked.
Please create github repo to show the problem, it is hard to say why module was not found
Okay
You can use this repository https://github.com/robosushie/repro.git To repro ... npm run package / npm run make copy the generated output distributable to another pc and then run the exe file.
Thanks and Regards Sushant
I have also tried the options mentioned in this comment https://github.com/webpack-contrib/node-loader/issues/12#issuecomment-334116820 but still got the same issue when testing it on a different module.
I have also tried other configuration options with node-loader and node-bindings-loader, https://github.com/webpack-contrib/node-loader/issues/22#issuecomment-652946395
I dont know what exactly wrong I am doing wrong. Regards Sushant
I have the problem with your example:
make: Entering directory '/home/evilebottnawi/IdeaProjects/repro/build'
make: *** No rule to make target 'Release/obj.target/libsdr//home/evilebottnawi/IdeaProjects/repro/addon/libsdr.o', needed by 'Release/obj.target/sdr.node'. Stop.
make: Leaving directory '/home/evilebottnawi/IdeaProjects/repro/build'
:disappointed:
When are you seeing issue? which command are you running?
I actually generated this project using the command "npx create-electron-app --template=webpack".
In this I have only addon the addon, external, jsconfig.json and bindings.gyp, and called the addon in main file.... The template had prebuild options with node-loader and @marshallofsound/webpack-asset-relocator-loader ... in webpack.rules.js file... it was also not working with the default configs... So I then tried looking in forums and tested with "native-ext-loader", "node-bindings-loader", "awesome-node-loader" but nothing worked.
I found two similar issues, and followed the methods they mentioned, but those were also not working https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/1258 https://github.com/webpack/webpack/issues/5762 https://github.com/webpack-contrib/node-loader/issues/12#issuecomment-334116820
I did not see this in my setup, can you try with node-gyp rebuild and then package it?
If you use webpack-asset-relocator-loader, you don't need node-loader, just remove it and use process.dlopen
Okay, I think both are necessary because this is currently mentioned in electron-forge documentation.

I will try with webpack-asset-relocator-loader and add process.dlopen and test it. Thanks