webpack-contrib / node-loader

node loader for native modules
MIT License
119 stars 43 forks source link

process.dlopen: The specified module could not be found #32

Closed its-dibo closed 3 years ago

its-dibo commented 3 years ago

I use node-loader to load .node files with webpack, however, it generates the output files as expected in dist folder.

// dist/file.js

__webpack_require__.p =""
process.dlopen(module, __dirname + "/" + __webpack_require__.p + "sharp.node");

and sharp.node exists in the same dir. but I got this error

node-loader:
Error: The specified module could not be found.
D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\ sharp.node

the path determined in the error message is correct and exists

minimal reproduction: https://github.com/lovell/sharp/issues/2517#issuecomment-767703678

alexander-akait commented 3 years ago

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\.node is invalid path, please create reproducible test repo and use the issue template

its-dibo commented 3 years ago

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\.node is invalid path, please create reproducible test repo and use the issue template

just typo, updated

alexander-akait commented 3 years ago

Please create reproducible test repo, I can't help you without additional information

its-dibo commented 3 years ago

repo: https://github.com/eng-dibo/ngx

the base webpack config file is located in the workspace's root.

the issue occures when you build:server of the project 'cms' to do that, run the following command from the workspace's root.

npm run build:server:dev --prefix projects/cms

additional info: I installed sharp on windows 8 with this cmd:

npm i sharp

I will try the following, may this help

npm install --arch=x64 --platform=linux sharp
alexander-akait commented 3 years ago

Why you use node-loader for browser target? It will not work, this loader only for node or electron all is fine, my mistake

alexander-akait commented 3 years ago

Anyway npm run build:server:dev --prefix projects/cms doesn't have this error (linux/ubuntu)

alexander-akait commented 3 years ago

I think sharp doesn't support windows@8

its-dibo commented 3 years ago

I think sharp doesn't support windows@8

it does, because I already used it before in the same laptop.

alexander-akait commented 3 years ago

If you don't have .node file, it means you really don't have it, there is no magic

alexander-akait commented 3 years ago

We use very simple logic https://github.com/webpack-contrib/node-loader/blob/master/src/index.js#L32

its-dibo commented 3 years ago

I have .node file, but the problem is that it fails to be loaded by process.dlopen

you can see this file in dist/cms/core/server/[hash].node

its-dibo commented 3 years ago

We use very simple logic https://github.com/webpack-contrib/node-loader/blob/master/src/index.js#L32

yes, that exactly what I see in the output file. but as the title suggests it is seem that the issue is caused when executing this function.

alexander-akait commented 3 years ago

This function from Node.js, we can't control execution here https://nodejs.org/api/process.html#process_process_dlopen_module_filename_flags

alexander-akait commented 3 years ago

Run this function on this file (sharp.node, inside dist), without webpack, just using simple Node.js script and look at result

its-dibo commented 3 years ago

New Bitmap Image

alexander-akait commented 3 years ago

No problems with loader as you can see

its-dibo commented 3 years ago

so, what are your suggestions?

alexander-akait commented 3 years ago

Something wrong with sharp on windows 8, I can't even reproduce it on virtual machine, update windows...

its-dibo commented 3 years ago

Something wrong with sharp on windows 8, I can't even reproduce it on virtual machine, update windows...

thank you, @alexander-akait for your efforts <3

alexander-akait commented 3 years ago

Can you try it on other machine under windows?

its-dibo commented 3 years ago

minimal reproduction: https://github.com/lovell/sharp/issues/2517#issuecomment-767703678

alexander-akait commented 3 years ago

Why do you use externals: [nodeExternals()]? It keep all modules from node_modules inside or you fix the problem using externals? Also do not forget to add node: { __dirname: false } in config for webpack@4 (fixed in webpack@5)