You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
The specified module could not be found. (.node) #1135
While building. Pkg throwed me some warnings about native modules
And I did as it told me to do. I copied it and moved to bin directory. So folder looks like this
However, when I launch executable, it throws me this error Error: The specified module could not be found. \\?\D:\WORK\bothub\discord-base-bot\canvas.node
@leerob@jesec@erossignon Seems that pkg isn't able to correctly bind .node files. Tests are passing and there are tests that are covering this, any clue what could be wrong? Maybe the PR change that allow to integrate .node binaries in the exe broke this someway?
to generate the binary,
then run the binary itself
$./pkg_issue_1335-linux
and got:
pkg/prelude/bootstrap.js:1359
throw error;
^
Error: /tmp/a06a6d1818170db6aa30d25ee7d26b2ea12cffd0b4dcf34aa3bde8d57a2406f3_canvas.node: invalid ELF header
at tryImporting (pkg/prelude/bootstrap.js:1736:37)
at process.dlopen (pkg/prelude/bootstrap.js:1762:5)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1248:18)
at Module.load (internal/modules/cjs/loader.js:1047:32)
at Function.Module._load (internal/modules/cjs/loader.js:935:14)
at Module.require (internal/modules/cjs/loader.js:1087:19)
at Module.require (pkg/prelude/bootstrap.js:1338:31)
at require (internal/modules/cjs/helpers.js:73:18)
at Object.<anonymous> (/snapshot/pkg_issue_1335/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (pkg/prelude/bootstrap.js:1433:22)
pkg seems to copy the canvas.node to a temporary folder before loading it .
pkg has currently no way to detect that external dll are need, the system dll loader is not aware of the pkg virtual file system.
A possibility would be to extract all files that are inside the folder in the same temporary folder as "canvas.node" binary is at runtime so that dll loader works as expected.
In fact, my mistake, I was mixing with a previous attempt on Windows, hence the invalid ELF header error.
I should have run dist/pkg_issue_1335-linux
and it works ! (on linux)
Running .\dist\pkg_issue_1335-win.exe on windows exhibit this issue:
Error: C:\Users\xxxxx\AppData\Local\Temp/671674c55d8bd6d5211863f8185778ec98f1063105350bf4a9de8639814155e9_canvas.node is not a valid Win32 application.
C:\Users\xxxxxx\AppData\Local\Temp/671674c55d8bd6d5211863f8185778ec98f1063105350bf4a9de8639814155e9_canvas.node
at tryImporting (pkg/prelude/bootstrap.js:1736:37)
at process.dlopen (pkg/prelude/bootstrap.js:1762:5)
@erossignon I still got this issue with pkg 5.3.2 on mac. No library found in tmp path. Error: dlopen(/var/folders/z6/fsq4vw8x7sq2ysb9rdsq4xf80000gn/T/3e57d87ecc7dcca3b8c85e1103e9b717e9d94f0583cad9042a73ef0aafe00c8d/canvas.node, 1): Library not loaded: @loader_path/librsvg-2.2.dylib Referenced from: /var/folders/z6/fsq4vw8x7sq2ysb9rdsq4xf80000gn/T/3e57d87ecc7dcca3b8c85e1103e9b717e9d94f0583cad9042a73ef0aafe00c8d/canvas.node Reason: image not found
But note, this is only a local/temporary fix as the resulting executable expects the library to be located at /opt/homebrew/... which might not be the case on another machine.
But I am also looking for a solution how to tell pkg to embed these dependencies as well. Is this about a missing dependency resolver for node files? @erossignon On Windows it's clear as the *.dll files are already stored in the node_modules directory, but why does this work on Linux?
This is still an issue on Windows. Executables packaged with pkg simply cannot "find" .node files when running on Windows. Even debugging with fs.existsSync() with the same file as what is passed to require() says the file exists, yet we keep getting the same ERR_DLOPEN_FAILED message.
I've tried every version of pkg going back to 5.0. I've also tried every possible fix/workaround I could find from reported issues. (including moving .node files and its dependencies to the exec path, adding stuff to the "assets" list in package.json, referencing the node file statically instead of a dynamic import, etc. nothing works, its just a broken feature).
In my case, my .node addon relies on external dlls that should be present alongside the .node file (glfw.node in my case, which requires opengl libraries).
Everything works fine on Linux, its just Windows that fails. I have a feeling the "The specified module could not be found" error message is misleading and that it actually fails on loading the external DLL files.
This is still an issue on Windows. Executables packaged with pkg simply cannot "find" .node files when running on Windows. Even debugging with fs.existsSync() with the same file as what is passed to require() says the file exists, yet we keep getting the same ERR_DLOPEN_FAILED message.
I've tried every version of pkg going back to 5.0. I've also tried every possible fix/workaround I could find from reported issues. (including moving .node files and its dependencies to the exec path, adding stuff to the "assets" list in package.json, referencing the node file statically instead of a dynamic import, etc. nothing works, its just a broken feature).
In my case, my .node addon relies on external dlls that should be present alongside the .node file (glfw.node in my case, which requires opengl libraries).
Everything works fine on Linux, its just Windows that fails. I have a feeling the "The specified module could not be found" error message is misleading and that it actually fails on loading the external DLL files.
I pretty much just distribute the release folder of .node libraries that can't be bundled with pkg, so far that's been skis-canvas and sharp
So right after I posted my previous message, I ran Dependency Walker on the .node file and noticed some native Windows API's were missing. I just "guessted" a solution and went ahead and installed both .net runtime and vc redist (just google them) and it magically worked.
Just leaving this here for others that may get stuck on the ERR_DLOPEN_FAILED messages.
So right after I posted my previous message, I ran Dependency Walker on the .node file and noticed some native Windows API's were missing. I just "guessted" a solution and went ahead and installed both .net runtime and vc redist (just google them) and it magically worked.
Just leaving this here for others that may get stuck on the ERR_DLOPEN_FAILED messages.
Note that your customers machines may need these too if they aren't installed.
Bro I'm still getting
pkg/prelude/bootstrap.js:1430
throw error;
^
Error: The specified module could not be found.
I've installed both those things as you've said! my pkg version is 5.5.2, node version: "16", windows x64, what exactly steps that I've to follow after installing those things you've specified?
So right after I posted my previous message, I ran Dependency Walker on the .node file and noticed some native Windows API's were missing. I just "guessted" a solution and went ahead and installed both .net runtime and vc redist (just google them) and it magically worked.
Just leaving this here for others that may get stuck on the ERR_DLOPEN_FAILED messages.
Note that your customers machines may need these too if they aren't installed.
I followed the way you said and found that the .node file depends on vcruntime140.dll. I am using windows server 2012R2 operating system. After installing VC++2015, it was successful.
Activity
gilvex commentedon Apr 15, 2021
I also tried to include native modules in
"assets"but it didn't change anythingrobertsLando commentedon Apr 15, 2021
@skaneprime are you using latest version?
gilvex commentedon Apr 15, 2021
@robertsLando

I was using 4.4.9. Updated to 4.5.1 But now it launches half of the code and just stops
with node
after building with pkg

gilvex commentedon Apr 15, 2021
Okay now here's detailed one. (Sorry, I'm kinda rushy guy)
When I'm not including (.node) files as assets it works but throws such errors

when I include them the same mistakes occur
robertsLando commentedon Apr 15, 2021
Try to provide a relative path to the nodes instead of using a full path, start from
./node_modules/..gilvex commentedon Apr 15, 2021
Same error

gilvex commentedon Apr 15, 2021
I tried to play with paths. It didn't change anything. Even copying native modules to another folder and adding them as asset
robertsLando commentedon Apr 15, 2021
@erossignon Any clue?
gilvex commentedon Apr 16, 2021
I even tried to include the whole module it self as an asset but the result is same
"node_modules/canvas/**/*"robertsLando commentedon Apr 16, 2021
@leerob @jesec @erossignon Seems that pkg isn't able to correctly bind
.nodefiles. Tests are passing and there are tests that are covering this, any clue what could be wrong? Maybe the PR change that allow to integrate .node binaries in the exe broke this someway?gilvex commentedon Apr 19, 2021
@erossignon Hi! Do you have any ideas?
erossignon commentedon Apr 22, 2021
So I've createc a simple nodejs project that includes canvas
package.json
It seems that canvas.node is no more a statically linked dll and requires a lot of dependent dll to be loaded:
I run
to generate the binary,
then run the binary itself
and got:
pkg seems to copy the canvas.node to a temporary folder before loading it .
pkg has currently no way to detect that external dll are need, the system dll loader is not aware of the pkg virtual file system.
A possibility would be to extract all files that are inside the folder in the same temporary folder as "canvas.node" binary is at runtime so that dll loader works as expected.
robertsLando commentedon Apr 22, 2021
I think that adding
./node_modules/canvas/build/Release/*in assets could fix the problemerossignon commentedon Apr 22, 2021
In fact, my mistake, I was mixing with a previous attempt on Windows, hence the
invalid ELF headererror.I should have run dist/pkg_issue_1335-linux
and it works ! (on linux)
Running
.\dist\pkg_issue_1335-win.exeon windows exhibit this issue:erossignon commentedon Apr 22, 2021
That might not be enough as those assets will have to be copied also where the
.nodefile is extracted.13 remaining items
fix .node loading issue on windows (vercel#1135)
erossignon commentedon May 2, 2021
@skaneprime can you confirm that issue is now resolved with [email protected] ?
gilvex commentedon May 2, 2021
let me rebuild it then
Yes! It works!!! Thank you very much!
yangchen08 commentedon Sep 22, 2021
@erossignon I still got this issue with pkg 5.3.2 on mac. No library found in tmp path.
Error: dlopen(/var/folders/z6/fsq4vw8x7sq2ysb9rdsq4xf80000gn/T/3e57d87ecc7dcca3b8c85e1103e9b717e9d94f0583cad9042a73ef0aafe00c8d/canvas.node, 1): Library not loaded: @loader_path/librsvg-2.2.dylib Referenced from: /var/folders/z6/fsq4vw8x7sq2ysb9rdsq4xf80000gn/T/3e57d87ecc7dcca3b8c85e1103e9b717e9d94f0583cad9042a73ef0aafe00c8d/canvas.node Reason: image not foundsebastianrath commentedon Sep 28, 2021
@yangchen08 you can fix this by using Homebrew.
brew install librsvgBut note, this is only a local/temporary fix as the resulting executable expects the library to be located at
/opt/homebrew/...which might not be the case on another machine.But I am also looking for a solution how to tell pkg to embed these dependencies as well. Is this about a missing dependency resolver for node files? @erossignon On Windows it's clear as the
*.dllfiles are already stored in the node_modules directory, but why does this work on Linux?prasheel888 commentedon Mar 8, 2022
how to resolve this canvas issue??
haroldiedema commentedon Jun 8, 2022
This is still an issue on Windows. Executables packaged with pkg simply cannot "find"
.nodefiles when running on Windows. Even debugging withfs.existsSync()with the same file as what is passed torequire()says the file exists, yet we keep getting the sameERR_DLOPEN_FAILEDmessage.I've tried every version of pkg going back to 5.0. I've also tried every possible fix/workaround I could find from reported issues. (including moving .node files and its dependencies to the exec path, adding stuff to the "assets" list in package.json, referencing the node file statically instead of a dynamic import, etc. nothing works, its just a broken feature).
In my case, my
.nodeaddon relies on external dlls that should be present alongside the.nodefile (glfw.node in my case, which requires opengl libraries).Everything works fine on Linux, its just Windows that fails. I have a feeling the "The specified module could not be found" error message is misleading and that it actually fails on loading the external DLL files.
Lucky38i commentedon Jun 8, 2022
I pretty much just distribute the release folder of .node libraries that can't be bundled with pkg, so far that's been
skis-canvasandsharpharoldiedema commentedon Jun 8, 2022
So right after I posted my previous message, I ran Dependency Walker on the
.nodefile and noticed some native Windows API's were missing. I just "guessted" a solution and went ahead and installed both.net runtimeandvc redist(just google them) and it magically worked.Just leaving this here for others that may get stuck on the
ERR_DLOPEN_FAILEDmessages.Links:
Note that your customers machines may need these too if they aren't installed.
prasheel888 commentedon Jun 18, 2022
Bro I'm still getting
pkg/prelude/bootstrap.js:1430
throw error;
^
Error: The specified module could not be found.
I've installed both those things as you've said! my pkg version is 5.5.2, node version: "16", windows x64, what exactly steps that I've to follow after installing those things you've specified?
BlitzKiiro commentedon Sep 25, 2022
I kinda found some work around this problem by excluding the module from the bundled .exe file.
What I did was to require the canvas module with its absolute path like this:
const Canvas = require(path.join(process.execPath, "../canvas"));then copying the Canvas module folder form node_modules and pasting it in the same directory with the final executable .exe file.
luliloveshe commentedon Sep 7, 2023
I followed the way you said and found that the .node file depends on vcruntime140.dll. I am using windows server 2012R2 operating system. After installing VC++2015, it was successful.