vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.6k stars 993 forks source link

Could not load the "sharp" module using the win32-x64 runtime #2975

Open meyvan opened 1 month ago

meyvan commented 1 month ago

Describe the bug When I try to create a new installation by following https://docs.vendure.io/guides/getting-started/installation/ guide I get the followinf error:

Error: Could not load the "sharp" module using the win32-x64 runtime
[worker] Possible solutions:
[worker] - Ensure optional dependencies can be installed:
[worker]     npm install --include=optional sharp
[worker]     yarn add sharp --ignore-engines
[worker] - Ensure your package manager supports multi-platform installation:
[worker]     See https://sharp.pixelplumbing.com/install#cross-platform
[worker] - Add platform-specific dependencies:
[worker]     npm install --os=win32 --cpu=x64 sharp
[worker] - Consult the installation documentation:

To Reproduce Steps to reproduce the behavior:

  1. Use Windows 10/11
  2. Follow guide https://docs.vendure.io/guides/getting-started/installation/
  3. Run npm run dev
  4. See error

Expected behavior Should run smoothly

Environment (please complete the following information):

Additional context

Sharp is only required if someone is using this strategy: https://docs.vendure.io/reference/core-plugins/asset-server-plugin/sharp-asset-preview-strategy

Why install it in the first place ? If someone wants to use it, let them install and use the strategy

Proposed Solution: Remove Sharp library as default and update docs to reflect the same

VitoorFranca commented 1 month ago

Install sharp if you are using asset server strategy:

npm install --include=optional sharp or yarn add sharp --ignore-engines

meyvan commented 1 month ago

Install sharp if you are using asset server strategy:

npm install --include=optional sharp or yarn add sharp --ignore-engines

Mate two things:

  1. Even if I run the above it's still the same issue
  2. I'm not using the SharpAssetPreviewStrategy, im using the S3AssetStorageStrategy

My question is why is included as part of core packages ? Since the entire architecture is strategy based why not let the end user install it IF AND ONLY IF they use SharpAssetPreviewStrategy ?

ziban commented 1 month ago

Install sharp if you are using asset server strategy:

npm install --include=optional sharp or yarn add sharp --ignore-engines

It's a mess when doing automated builds because you depend on what's defined in package.json

michaelbromley commented 1 month ago

Hi @meyvan, thanks for the report

Regarding the error itself, it may be the same as reported here

My question is why is included as part of core packages ? Since the entire architecture is strategy based why not let the end user install it IF AND ONLY IF they use SharpAssetPreviewStrategy ?

When you use @vendure/create we do include some non-core plugins that (usually) make the starting experience smoother.

We do not ship any other asset preview strategy than the sharp one, which means that if we didn't include it in a standard installation, then if you try to upload images we would not be able to create previews.

Can you try updating to Node v20 and see if that makes any difference?

meyvan commented 1 month ago

We do not ship any other asset preview strategy than the sharp one, which means that if we didn't include it in a standard installation, then if you try to upload images we would not be able to create previews.

Can you try updating to Node v20 and see if that makes any difference?

@michaelbromley I get it.

But here is my visible confusion:

Screenshot (2)

I see previews being made as optional params, which led me to assume, those are in fact optional

Second, the left panel shows Sharp Preview Strategy similar to AssetStorage and LocalStorage and underneath it. It led me to believe SharpPreview is a separate strategy and not part of Assets Storage.

Maybe can it be included as a submenu underneath AssetStorageStragety ?

meyvan commented 1 month ago

I was under the assumption that if no preview related configurations are sent in, then no image will be transformed

meyvan commented 1 month ago

Still getting the same error mate, tried 20 and 22

meyvan commented 1 month ago

Got it. To anyone who is using windows, use the below for local development and make sure to install the linux based when you are deploying. Not a great solution but the bug from Sharp as mentioned by @michaelbromley makes it as a necessity

npm install sharp
npm install --force @img/sharp-win32-x64
ziban commented 1 month ago

@meyvan please reopen it. I'm experiencing the same issue on a linux machine, and I think having a long term solution helps.

@michaelbromley it breaks between version 2.1.9 and 2.2.0. I had to upgrade from an earlier version to use a plugin and ran into this error. Screen Shot 2024-07-30 at 3 14 33 PM

michaelbromley commented 1 month ago

in v2.2.0 we upgraded the Sharp version, which is why the issue now appears.

I think a work-around could be that we add the --include=optional flag in the @vendure/create install command. The strange thing is that I don't run into this when testing locally. I'll have to see how I can reproduce and therefore test any fixes.

ziban commented 1 month ago

Some thoughts on reproducing the error:

  1. Maybe installing an earlier version(2.0/2.1) then upgrading might cause the issue.
  2. Using yarn - was able to solve the issue by moving to npm, and running npm install --cpu=x64 --os=linux --libc=glibc sharp and npm install --include=optional sharp