sharp: Vercel only: 0.33.0: error Could not load the "sharp" module using the linux-x64 runtime
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
- Running
npm install sharpcompletes without error. - Running
node -e "require('sharp')"completes without error.
If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
- I am using the latest version of
sharpas reported bynpm view sharp dist-tags.latest.
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
What are the steps to reproduce?
Running sharp on Vercel breaks after updating from 0.32.6 to 0.33.0
ERROR Error: Could not load the "sharp" module using the linux-x64 runtime
Downgrading to 0.32.6 for now
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 3
- Comments: 44 (18 by maintainers)
Commits related to this issue
- Temporary fix for https://github.com/lovell/sharp/issues/3870 — committed to DarthGigi/MinionAH by DarthGigi 7 months ago
- Lock shape to 0.32.6 Latest shape failed in Vercel. https://github.com/lovell/sharp/issues/3870 — committed to llun/activities.next by llun 7 months ago
- chore: downgrade sharp package due to: https://github.com/lovell/sharp/issues/3870 — committed to Mexidense/uml2code by Mexidense 7 months ago
- add @vercel/nft >0.26.1 to fix https://github.com/lovell/sharp/issues/3870 — committed to ryngonzalez/ryngonzalez.com by ryngonzalez 4 months ago
Facing same issue on Vercel. Confirmed that my Vercel and local env are running node version =
18.17.1I have already install
sharpbynpm install --force @img/sharp-linux-x64When I run locally on a Linux machine (ArchLinux x64) it works fine both on build and runtime; while on Vercel build success but the serverless function call throw the following exception at runtime:update: downgrade to
0.32.6works (fyi who really need a workaround)After some investigation, if I change https://github.com/lovell/sharp/blob/main/lib/sharp.js#L24 to
require('@img/sharp-darwin-arm64/sharp.node')@vercel/nftcollects the correspondingsharp-darwin-arm64.nodefile correctly. I opened the issue at https://github.com/vercel/nft/issues/371.FYI it’s not just on Vercel, we encountered this issue yesterday (caused an incident in prod) on AWS Lambda using the Node 18 runtime because we install latest (0.33.0 in this case) on every deployment. We fixed it by pinning sharp to 0.32, but didn’t investigate further.
👋🏽 Not only on Vercel since I’ve just had the issue locally on my Mac, after upgrading.
@JClackett I think Vercel uses
@vercel/nftunder the hood so perhaps they have not yet updated their build infrastructure with the latest version. You’ll need to ask Vercel support about this.@jahirfiquitiva This issue relates only to Vercel. If you’re seeing this problem locally, please open a new installation issue and answer all the questions.
@katywings This issue relates only to Vercel. If you’re seeing this problem locally, please open a new installation issue and answer all the questions. This will help me to gather lots of information from as many people as possible before starting to look for patterns.
@devunt Great detective work, thank you, it confirms that deployment logic run within Vercel is causing this problem.
As a quick fix for now you could install an older version of sharp manually in your app. I tried with
sharp@0.32.6and it should remove the error from Vercel.I’ve renamed this issue so it can focus on those experiencing problems on Vercel only. If you are experiencing it anywhere else, please open a new issue.
I genuinely want to help people, and the best way to do that right now is for you to give me lots of information, but not all in the same issue all at once. Lots of separate issues that I can use to find out specifics about each failing environment will allow me to help you to help others. Thank you.
Was also experiencing this issue and updating Node fixed it (
18.16.1>18.19.0).sharp@0.32.6
This worked for me, I had the same issue with Next.js on Vercel and Netlify.
I can confirm getting rid of
--omit=optionalfixed my issue, thanks@lovell I figured it out, I just was pretty unlucky 😅: the node version I was running was v19.8.1 which exactly is missing in the range at https://github.com/lovell/sharp/blob/545e09fad2e10eb9d21c03fe4ad73196e36ffc98/npm/linux-x64/package.json#L32 After switching to node v20.3.0,
pnpm install sharpautomatically installed@img/sharp-linux-x64and the error went away.Appreciate for the pointing the right direction. However I just wanna let maintainers and others to know that I suspect this is a Vercel (and its library) issue, not a sharp specific issue.
In terms of Vercel, my suspicion is that there is something slightly different happening during the remote build that is preventing the right dependencies being installed. Paging @styfle who is always very helpful and may be able to provide more information about Vercel-internal systems for those who are experiencing this problem on Vercel only.