vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.32k stars 1.01k forks source link

Not working with sharp again "Cannot include directory %1 into executable." #1918

Closed rightaway closed 11 months ago

rightaway commented 1 year ago

What version of pkg are you using?

5.7.0

What version of Node.js are you using?

16.15.0

What operating system are you using?

linux

What CPU architecture are you using?

amd64

What Node versions, OSs and CPU architectures are you building for?

node16-linux-64

Describe the Bug

When I run pkg there are warnings

> pkg@5.7.0
compression:  GZip
> Warning Cannot include directory %1 into executable.
  The directory must be distributed with executable as %2.
  %1: node_modules/sharp/build/Release
  %2: path-to-executable/sharp/build/Release
> Warning Cannot include directory %1 into executable.
  The directory must be distributed with executable as %2.
  %1: node_modules/sharp/vendor/lib
  %2: path-to-executable/sharp/vendor/lib

To Reproduce

Try running pkg with sharp as a dependency. You can add these to package.json which I thought would fix it but it didn't.

"assets": [
  "node_modules/sharp/build/Release",
  "node_modules/sharp/vendor/lib"
]
"assets": [
  "node_modules/sharp/build/Release/sharp-linux-x64.node"
]

According to https://github.com/vercel/pkg/issues/1075 sharp should be working but it's not.

https://github.com/vercel/pkg/issues/229 is a similar issue but like many issues in this vercel pkg repository it got closed automatically even though it's still not working.

robertsLando commented 1 year ago

Try to use "node_modules/sharp/**" as asset. Also even if you see that warning it doesn't mean the binary will not work

hjyssg commented 1 year ago

I used the solution provided above, didnt work. I hope pkg team could just provide some kind of example project for this issue. Since so many issue about sharp and sqlite. image

sbochkar commented 1 year ago

Also facing this issue.

Adding "node_modules/sharp/**" to asset seems to work when compiling for the linux platform. This is the platform where my development happens.

However, it does not help with cross compiling for win platform.

Below is what I get when I try to run exe on Windows platform.

PS C:\.......
pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error:
Something went wrong installing the "sharp" module

The specified module could not be found.
C:\...\AppData\Local\Temp\pkg\028b5dfb4c795afee359660beef08cc4cf2733dc7f19bfeafc7a8365c82adb97\sharp\build\Release\sharp-win32-x64.node

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current win32-x64 runtime: "npm install --platform=win32 --arch=x64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (C:\snapshot\project-name\node_modules\sharp\lib\sharp.js:37:9)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:834:12)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\snapshot\project-name\node_modules\sharp\lib\constructor.js:11:1)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)

Node.js v18.5.0

Checking the AppData folder shows that the files ARE in that folder.

PS > ls C:\...\AppData\Local\Temp\pkg\028b5dfb4c795afee359660beef08cc4cf2733dc7f19bfeafc7a8365c82adb97\sharp\build\Release\

    Directory: C:\...\AppData\Local\Temp\pkg\028b5dfb4c795afee359660beef08cc4cf2733dc7f19bfeafc7a8365c82adb97\sharp\build\Release

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2023-05-26   1:51 PM         369664 libvips-cpp.dll
-a----        2023-05-26   1:51 PM         248224 sharp-linux-x64.node
-a----        2023-05-26   1:51 PM         248224 sharp-linux-x64.node.win.v18.5.0
-a----        2023-05-26   1:51 PM         406016 sharp-win32-x64.node
-a----        2023-05-26   1:51 PM         406016 sharp-win32-x64.node.win.v18.5.0
baparham commented 1 year ago

did you try reinstalling sharp for windows before you compiled your pkg binary? E.g. npm install --platform=win32 --arch=x64 sharp as the error message suggests.

Sharp uses native .node files that are compiled and platform specific, so you are trying to run a linux compiled native node module on a windows machine.

Do you have the ability to build your windows pkg distributable on windows itself natively?

nononoyeah commented 1 year ago

I had the same problem,When I change sharp version to 0.29.3 and add "node_modules/sharp/*/*." to pkg assets, then it works。 image

image

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] commented 11 months ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.