Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
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

Closed

Description

@gilvex

While building. Pkg throwed me some warnings about native modules
image

And I did as it told me to do. I copied it and moved to bin directory. So folder looks like this
image

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

image

What's the issue?

in package.json
"pkg": { "scripts": [ "./dist/core/**/*.js", "./dist/services/**/*.js", "./dist/plugins/**/*.js" ], "targets": [ "node14-win-x64" ] }

Activity

  1. gilvex commented on Apr 15, 2021

    @gilvex
    Author

    I also tried to include native modules in "assets" but it didn't change anything

  2. robertsLando commented on Apr 15, 2021

    @robertsLando
    Contributor

    @skaneprime are you using latest version?

  3. gilvex commented on Apr 15, 2021

    @gilvex
    Author

    @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
    image

    after building with pkg
    image

  4. gilvex commented on Apr 15, 2021

    @gilvex
    Author

    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
    image

    when I include them the same mistakes occur

    image

  5. robertsLando commented on Apr 15, 2021

    @robertsLando
    Contributor

    Try to provide a relative path to the nodes instead of using a full path, start from ./node_modules/..

  6. gilvex commented on Apr 15, 2021

    @gilvex
    Author

    Try to provide a relative path to the nodes instead of using a full path, start from ./node_modules/..

    Same error
    image

  7. gilvex commented on Apr 15, 2021

    @gilvex
    Author

    I tried to play with paths. It didn't change anything. Even copying native modules to another folder and adding them as asset

  8. robertsLando commented on Apr 15, 2021

    @robertsLando
    Contributor

    @erossignon Any clue?

  9. gilvex commented on Apr 16, 2021

    @gilvex
    Author

    I even tried to include the whole module it self as an asset but the result is same "node_modules/canvas/**/*"

  10. robertsLando commented on Apr 16, 2021

    @robertsLando
    Contributor

    @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?

  11. gilvex commented on Apr 19, 2021

    @gilvex
    Author

    @erossignon Hi! Do you have any ideas?

  12. erossignon commented on Apr 22, 2021

    @erossignon
    Contributor

    So I've createc a simple nodejs project that includes canvas

    package.json

    {
      "name": "pkg_issue_1335",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "bin": "./index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "pkg42": "npx pkg -t host package.json"
      },
      "pkg": {
        "scripts": "index.js",
        "assets": "node_modules/canvas/build/Release/*",
        "outputPath": "dist"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "canvas": "^2.7.0"
      }
    }
    
    // ìndex.js
    const canvas = require("canvas");
    console.log("42");

    It seems that canvas.node is no more a statically linked dll and requires a lot of dependent dll to be loaded:

    ls ./node_modules/canvas/build/Release/
    canvas.exp       libbrotlicommon.dll     libexpat-1.dll       libgdk_pixbuf-2.0-0.dll  libgraphite2.dll   libpango-1.0-0.dll       libpng16-16.dll      obj
    canvas.ilk       libbrotlidec.dll        libffi-7.dll         libgif-7.dll             libharfbuzz-0.dll  libpangocairo-1.0-0.dll  librsvg-2-2.dll      zlib1.dll
    canvas.lib       libbz2-1.dll            libfontconfig-1.dll  libgio-2.0-0.dll         libiconv-2.dll     libpangoft2-1.0-0.dll    libstdc++-6.dll
    canvas.node      libcairo-2.dll          libfreetype-6.dll    libglib-2.0-0.dll        libintl-8.dll      libpangowin32-1.0-0.dll  libthai-0.dll
    canvas.node.bak  libcairo-gobject-2.dll  libfribidi-0.dll     libgmodule-2.0-0.dll     libjpeg-8.dll      libpcre-1.dll            libwinpthread-1.dll
    canvas.pdb       libdatrie-1.dll         libgcc_s_seh-1.dll   libgobject-2.0-0.dll     liblzma-5.dll      libpixman-1-0.dll        libxml2-2.dll
    

    I run

    npx pkg package.json
    

    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.

  13. robertsLando commented on Apr 22, 2021

    @robertsLando
    Contributor

    I think that adding ./node_modules/canvas/build/Release/* in assets could fix the problem

  14. erossignon commented on Apr 22, 2021

    @erossignon
    Contributor

    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)
    
  15. erossignon commented on Apr 22, 2021

    @erossignon
    Contributor

    I think that adding ./node_modules/canvas/build/Release/* in assets could fix the problem

    That might not be enough as those assets will have to be copied also where the .node file is extracted.

  16. 13 remaining items

  17. erossignon commented on May 2, 2021

    @erossignon
    Contributor

    @skaneprime can you confirm that issue is now resolved with [email protected] ?

  18. gilvex commented on May 2, 2021

    @gilvex
    Author

    let me rebuild it then

    @skaneprime can you confirm that issue is now resolved with [email protected] ?

    Yes! It works!!! Thank you very much!

  19. yangchen08 commented on Sep 22, 2021

    @yangchen08

    @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

  20. sebastianrath commented on Sep 28, 2021

    @sebastianrath

    @yangchen08 you can fix this by using Homebrew.

    brew install librsvg

    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?

  21. prasheel888 commented on Mar 8, 2022

    @prasheel888

    how to resolve this canvas issue??

  22. haroldiedema commented on Jun 8, 2022

    @haroldiedema

    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.

  23. Lucky38i commented on Jun 8, 2022

    @Lucky38i

    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

  24. haroldiedema commented on Jun 8, 2022

    @haroldiedema

    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.

    Links:

    Note that your customers machines may need these too if they aren't installed.

  25. prasheel888 commented on Jun 18, 2022

    @prasheel888

    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.

    Links:

    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?

  26. BlitzKiiro commented on Sep 25, 2022

    @BlitzKiiro

    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.

  27. luliloveshe commented on Sep 7, 2023

    @luliloveshe

    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.

    Links:

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions