Open pdehne opened 3 years ago
Can you create simple reproducible test repo?
Sure. Here is a test repo: https://github.com/pdehne/node-loader-test
To reproduce please open a console in the project folder of the repo and run:
npm install
npm run configureaddon
npm run buildaddon
npm run watch
Then open a second console in the main project folder and run:
npm run start:watch
You will see the error message in the Electron console window:
Stop both npm processes using CTRL-c then change node-loader versions:
npm remove node-loader
npm install node-loader@0.6.0 --save-dev
Start watch / start:watch in their respective consoles again. The native node module is loaded successfully and you will see "Hello World from Node.js" in the Electron console:
Weird, using:
npm remove node-loader
npm install node-loader@0.6.0 --save-dev
still have the problem:
Uncaught Error: Cannot open /path/to/node-loader-testazazaq/build/Release/nodeloadertest.node: Error: Module did not self-register: '/home/evilebottnawi/IdeaProjects/node-loader-testazazaq/build/Release/nodeloadertest.node'.
Maybe something buggy with cpp code?
Did you run npm run configureaddon / npm run buildaddon? The repo targets Electron 10.1.1 and will only build the addon using the right target version if you use these commands.
Did you run npm run configureaddon / npm run buildaddon?
Yes
Can you try other version of Electron
or node?
I upgraded the repo to Electron 11.3.0. I also streamlined the installation process to show first that it is working with 0.6.0. Please clone the repo into a new folder then run:
npm install
npm run watch
Open a second console and run
npm run start:watch
You should see "Hello World from Node.js" in the Electron console, just like in the screenshot above. If this works please first abort the two npm commands. Then, in one of the consoles run:
npm remove node-loader
npm install node-loader@latest
And again run npm run watch / npm run start:watch in the two consoles. You should see the error message from the screenshot above.
Can you reproduce?
Thanks, I will look at this in near future
Problem here: https://github.com/webpack-contrib/node-loader/blob/master/src/index.js#L32:
__dirname
is /path/to/node-loader/node_modules/electron/dist/resources/electron.asar/renderer
publicPath
is http://localhost:8084/
name
is build/Release/nodeloadertest.node
We contact them so you just have invalid path. But here two weird things - __dirname
and publicPath
, maybe we can generate relative paths to module.
Just interesting why you need this loader, because you can replace this loader using:
try {
process.dlopen(module, path.resolve(__dirname, './path/to/file.ext'));
} catch (error) {
// logging
}
To be honestly we should deprecate it in favor simple code above
Expected Behavior
I am using a custom native node module in my Electron application. When using node-loader 0.6.0 it is loading fine. When using node-loader 1.0.2 with the very same node module (no recompilation) I get an error.
Actual Behavior
The error thrown is:
soniccore.node:5 Uncaught Error: node-loader: Error: Invalid package C:\d\sw\trunk\SonicCare\node_modules\electron\dist\resources\electron.asar at Object../build/Release/soniccore.node (soniccore.node:5)
Code