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.
Bundling sharp doesn't work anymore since updating to 4.5.0 #1075
Copy link
Copy link
Closed
Description
Since updating to version 4.5.0 it is not possible to bundle sharp anymore. Previously this was fairly simple, by just copying the node_modules/sharp folder next to the build output. But this doesn't work anymore giving the following error:
Error:
Something went wrong installing the "sharp" module
File '/**/test/node_modules/sharp/build/Release/libvips-cpp.so.42' was not included into executable at compilation stage. Please recompile adding it as asset or script.
- Remove the "node_modules/sharp" directory then run
"npm install --ignore-scripts=false --verbose" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues
at Object.<anonymous> (/snapshot/test/node_modules/sharp/lib/constructor.js:34:9)
at Module._compile (pkg/prelude/bootstrap.js:1329:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1218:10)
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:1234:31)
at require (internal/modules/cjs/helpers.js:73:18)
at Object.<anonymous> (/snapshot/test/node_modules/sharp/lib/index.js:3:15)
at Module._compile (pkg/prelude/bootstrap.js:1329:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1218:10)
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:1234:31)
at require (internal/modules/cjs/helpers.js:73:18)
I'm fairly convinced this has to do with #837 or #1066 or maybe a combination of both.
Looking at the below error message running in CI, it seems that prebuild-install is not correctly installed or referenced, this has been added in #1066:
> [email protected]
> Fetching base Node.js binaries to PKG_CACHE_PATH
> 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
> 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
/bin/sh: 1: /builds/test/node_modules/pkg/node_modules/.bin/prebuild-install: not found
/bin/sh: 1: /builds/test/node_modules/pkg/node_modules/.bin/prebuild-install: not found
I'm mentioning both @david-mohr as well as @geekuillaume hoping they have a suggestion on how to fix this.
On a sidenote; this seems to me a breaking change so 5.0.0 would have been a more logical version for this release I suppose.
Reacted by Fabien, ycnmhd, Daniel Lando and Raj Ajwaliya
Metadata
Metadata
Assignees
Labels
No labels
Activity
david-mohr commentedon Mar 23, 2021
have you run
yarnto ensure that prebuild-install is actually installed?jesec commentedon Mar 23, 2021
If the mentioned changes are indeed breaking, I think we would have to revert them immediately and release a new version.
First, I would wait for a while for responses from the related parties, and see if there is a misconfiguration or if the changes can be tweaked to be non-breaking.
@pkeuter mentioned
just copying the node_modules/sharp folder next to the build output. Is this "load from outside" way previously supported?Any thoughts? @leerob @robertsLando
leerob commentedon Mar 23, 2021
Before doing any reverting, would need to verify and confirm it is indeed a breaking change. I'm not convinced those two PRs are related yet but would love to see the investigation here.
david-mohr commentedon Mar 23, 2021
prebuild-installis definitely in the package.json. @pkeuter how did you upgrade and does running 'yarn' ornpm ifix the issue?pkeuter commentedon Mar 23, 2021
I see it is in the package.json and it is also in the package-lock.json (I'm using npm):
and this is top-level the prebuild-install:
This was running in CI so there was no node_modules folder. No cache or something either.
When I look in the folder referenced
/home/peter/test/node_modules/pkg/node_modules/.bin/I don't see the binary either. I do see it a bit higher in/home/peter/test/node_modules/.bin. This probably is because of the flattening procedure that npm uses (see https://docs.npmjs.com/cli/v7/configuring-npm/folders). I am not sure if this differs from yarn but this seems to be a logical structure.david-mohr commentedon Mar 23, 2021
@pkeuter ah yes, I see what you mean now. Here's the target reference https://github.com/vercel/pkg/blob/master/lib/producer.js#L100. As you say,
yarnhandles this differently which is why it worked fine during testing. I also have mypkginstall globally.If you know how to change the path to handle any combination of situations (local/global, yarn/npm) that would be great.
pkeuter commentedon Mar 24, 2021
@david-mohr I do not know a solution right away, but the fact is that this is, indeed, a breaking change so it might be useful to revert the change in a new release until this has been resolved. Because pkg is currently broken for npm users that use native modules.
david-mohr commentedon Mar 24, 2021
@pkeuter I think this can be patched to work with both
npmandyarn, but if it needs to be backed out, that's fine too.@leerob guess it's your call. To fix this, the function can use existsSync to hunt around for the path. Otherwise just back it out, it doesn't seem that other users are interested in cross-platform support, so it's not really a helpful patch.
leerob commentedon Mar 25, 2021
I'm sorry you're having this issue @pkeuter☹️ It currently appears it's isolated to one report. Given that, I'd say we patch forward. Cross-platform support seems like something we would want to support.
JeffJassky commentedon Mar 26, 2021
The prebuild-install problem:
The path to the prebuild script is being built incorrectly. The error is in producer.js
pkg/lib/producer.js
Line 135 in f08d083
A Workaround:
I got it to resolve the correct path by changing that line to:
const prebuild = _path.default.join(process.cwd(), './node_modules/.bin/prebuild-install');. After that, the prebuild-install script path was correct - and it was being executed successfully.However... The prebuild script shows a warning
prebuild-install WARN install No prebuilt binaries found (target=v12.2.0 runtime=node arch=x64 libc= platform=win32)Manually Installing cross-platform prebuilt binaries:
So I installed my native module (sqlite3) manually using
npm install sqlite3 --arch=x64 --platform=win32which resulted in a very happy lookingSuccess: "/Users/jeffjassky/Projects/StoryFolderDesktop/node_modules/sqlite3/lib/binding/napi-v3-win32-x64/node_sqlite3.node" is installed via remoteUnfortunately:
When running pkg I still got the same error:
prebuild-install WARN install No prebuilt binaries found (target=v12.2.0 runtime=node arch=x64 libc= platform=win32)as if it doesn't recognize or include the newly installed module.My guess is that the target version was incorrect - but it's hard to know for sure. When I tried adding the
--target=v12.2.0flag I got a nastyUnsupported target version: v12.2.0error.So I tried manually added the module as an asset in package.json
When I run my packaged .exe on Windows I can see that the file indeed gets included, but I get this error:
Caught exception: Error: The specified module could not be found. C:\snapshot\StoryFolderDesktop\node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.nodeSo, lastly, I copied the node_sqlite3.node file into
path-to-executable/node_modules/sqlite3/lib/binding/napi-v3-win32-x64/node_sqlite3.nodealong side the executable and that finally seems to work, as inelegant as it is.So, for some reason, it can't locate the module even though it's right there in the snapshot - but it works when the module is placed alongside it.
robertsLando commentedon Mar 26, 2021
@JeffJassky Usually this kind of problems are fixed by dictionaries. You need to edit this https://github.com/vercel/pkg/blob/master/dictionary/sqlite3.js see an example here: https://github.com/vercel/pkg/blob/master/dictionary/puppeteer.js
JeffJassky commentedon Mar 26, 2021
@robertsLando I sort-of understand. These are package-specific configs for pkg - though I don't precisely know what I should put in there - 'cause I don't quite understand what the problem is, to begin with.
robertsLando commentedon Mar 26, 2021
I'm not the author of this package I have just take a general lookup of the code and from what I have understand that's a collection of package-specific fixes. With that you can specify patches (replace/add/remove code from files) and or additional assets/scripts to add for a specific package like:
In your case I think a possible fix could be adding the assets needed here in the sqlite3 dictionary, something like:
Give this a try and let me know :)
JeffJassky commentedon Mar 26, 2021
@robertsLando After looking into it further, the .node module is actually getting included in the snapshot - in the exact correct location. Hmm... the plot thickens.
Seems to be related directly to #1075, possibly #894, and #687
robertsLando commentedon Mar 26, 2021
We might check where the lookup fails so. Based on what I understand native node modules behaves different then normal assets, them are copied in a temporary folder iin order to be used, maybe the lookup or the copy fails somewhere. That feature has been added in #837. Did you alo try to put the node addon in the same root dir of the application to see if that works?
The magic happens here: https://github.com/vercel/pkg/pull/837/files#diff-0c3f42fd6825d8d5b4d0422402a89ff11dc1d1cfb52ee5901f4774e503783c27R1598
45 remaining items
rightaway commentedon Jul 24, 2021
@avpavp No luck. @robertsLando says it should work in the latest version but that's definitely not true.
avpavp commentedon Jul 24, 2021
@rightaway Same experience here. No success with [email protected] (current version at time of writing)
By using bits and pieces of @webdevog repo mentioned above, I seem to be making progress using [email protected]. My exe runs now, I just need to make sure everything is actually working...
john-yick commentedon Aug 10, 2021
I see the same issue with [email protected] it throws the as shown below, code runs fine from node directly:
leadwolf commentedon Aug 15, 2021
Looking at the sharp repo, in
binding.gypthey link tolibvips-cpp.so.42with a relative path:The problem is that when importing
sharp.node, pkg copies it to a temporary folder and libvips can't be resolved from that location. As fallback, pkg tries to find the missing file in the same virtual directory as the .node file, and copies it to the temporary folder. This won't work because at build time libvips isn't in the same directory as sharp.node, so it won't end up in the same virtual directory either. But even if we did manage to get libvips into the same virtual directory and have pkg copy it to the temporary folder, the import will still not work because it is not at the expected relative path:../../vendor....robertsLando commentedon Sep 29, 2021
@leadwolf I think you detected the real problem. I also tried to move sharp into the same directory with no luck, I also tried adding both folders to assets:
and the entire folder:
Did you find a workaround to this? @jesec @erossignon suggestions?
This should be handled here: https://github.com/vercel/pkg/blob/main/prelude/bootstrap.js#L2035 but for some reason it's not working as expected
robertsLando commentedon Sep 29, 2021
IMO what we should do is to copy the entire module folder instead of just the module, I will see if I can make a PR
fix: better support of `.node` files
robertsLando commentedon Sep 29, 2021
For anyone interested in this a fix is available with #1321
bootstrap: better support of `.node` files (#1321)
[pkg] add yarn/npm build issue to script...
better sanitize modules path
rightaway commentedon Jul 15, 2022
@robertsLando Is it still working for you? An error is happening again #1692.
robertsLando commentedon Jul 15, 2022
It's working for me. Try using
rightaway commentedon Jul 16, 2022
@robertsLando I tried again and it's actually working even without
"assets". But when building I get these warnings. The same happened in #229. Do you know the cause?