Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not load the "sharp" module using the linux-x64 runtime[Fixed] #2858

Closed
callumhemming opened this issue May 19, 2024 · 8 comments
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@callumhemming
Copy link
Contributor

Describe the bug
Using pnpm in linux to install Vendure, I came across this error after the install script, changing npm to pnpm in the package.json and running pnpm dev

[worker] Error: Could not load the "sharp" module using the linux-x64 runtime
[worker] Possible solutions:
[worker] - Please upgrade Node.js:
[worker]     Found 19.7.0
[worker]     Requires ^18.17.0 || ^20.3.0 || >=21.0.0
[worker] - Consult the installation documentation:
[worker]     See https://sharp.pixelplumbing.com/install
[worker]     at Object.<anonymous> (/home/{{user}}/vendure/node_modules/sharp/lib/sharp.js:114:9)
[worker]     at Module._compile (node:internal/modules/cjs/loader:1275:14)
[worker]     at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
[worker]     at Object.require.extensions.<computed> [as .js] (/home/{{user}}/vendure/node_modules/ts-node/src/index.ts:1608:43)
[worker]     at Module.load (node:internal/modules/cjs/loader:1133:32)
[worker]     at Function.Module._load (node:internal/modules/cjs/loader:972:12)
[worker]     at Module.require (node:internal/modules/cjs/loader:1157:19)
[worker]     at require (node:internal/modules/helpers:119:18)
[worker]     at Object.<anonymous> (/home/{{user}}/vendure/node_modules/sharp/lib/constructor.js:10:1)
[worker]     at Module._compile (node:internal/modules/cjs/loader:1275:14)

My node version was good etc. I'm thinking it's a problem with how WSL is configured as sharp seemed to be fetching the wrong binaries.

I was able to fix this problem by running pnpm install sharp --config.platform=linux --config.architecture=x64

This let me run the the server like normal :)

I wonder if this could be prevented in the package.json somehow, or adding a little debug statement to prompt the user to try installing sharp with the specific config above, if we fail to import sharp in (p)npm dev

Failing that, a line in the readme would be nice :)

To Reproduce
Steps to reproduce the behavior:

  1. Be on windows 10, running WSL(Distro specified below)
  2. Run the vendure install script via pnpm, succeed
  3. Switch the 'npm' references in the scripts to 'pnpm'
  4. Run pnpm dev
  5. (Potentially) See error

Expected behavior
The server to start up normally

Environment (please complete the following information):

  • @vendure/core version: 2.2.4
  • Nodejs version: v19.7.0
  • Database (mysql/postgres etc): sqlite3 9.6.0

Additional context
WSL linux distro:
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

@callumhemming callumhemming added the type: bug 🐛 Something isn't working label May 19, 2024
@oidt
Copy link
Contributor

oidt commented May 20, 2024

Vendure suppose to work with even numbers of nodejs as stated in the documentation. (https://docs.vendure.io/guides/getting-started/installation/ first bullet)
As in the code says: Requires ^18.17.0 || ^20.3.0 || >=21.0.0
18 or 20 or 21 and higher
You have 19. Please upgrade or downgrade

@callumhemming
Copy link
Contributor Author

I don't think it's a node version issue, I switched to each version listed whilst debugging and no difference. Seems to be a problem with my package manager fetching the wrong sharp binary

@oidt
Copy link
Contributor

oidt commented May 21, 2024

I understand, still a lot of people have the same problem under the sharp repo. lovell/sharp#3870 (comment) solved by correct version.
do you also have the output of the error of other versions? this error suggests wrong node version.
Maybe we can create a common errors section in the docs? You can make a PR for it if you want the docs are part of the repo

@TonyRice
Copy link

This issue has completely taken out my build.

I don't think it's a node version issue, I switched to each version listed whilst debugging and no difference. Seems to be a problem with my package manager fetching the wrong sharp binary

I am currently running into the same issue. Replacing the SharpAssetPreviewStrategy does not work either. I've gotten it to work locally a few times, but I couldn't tell you how I did. My node versions are correct. It definitely seems as if it's an issue with the way it detects dependencies.

I'm using yarn btw

@TonyRice
Copy link

What fixed this for me, was updating my version of yarn.

@callumhemming
Copy link
Contributor Author

callumhemming commented May 21, 2024

I understand, still a lot of people have the same problem under the sharp repo. lovell/sharp#3870 (comment) solved by correct version. do you also have the output of the error of other versions? this error suggests wrong node version. Maybe we can create a common errors section in the docs? You can make a PR for it if you want the docs are part of the repo

I'd love to make a PR for it! I'll look into it, add my solution (although I'm sure there's a more eloquent way of forcing sharp to pick the right binary via the package.json, although I haven't found a solution )

And I'll add @TonyRice solution to update yarn above. Tony, do you mind if I loop you into the PR to elaborate on your solution? Glad updating yarn worked for you! I tried updating pnpm and npm but I'm up to date with both so no dice, gonna probs add a post install script into my repo to specifically install sharp for my OS

@callumhemming
Copy link
Contributor Author

I'm assuming changing node version is the correct solution and I'm dealing with some WSL weirdness, I'll add my solution as an unrecommended solution

@callumhemming
Copy link
Contributor Author

Created PR here :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants