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 sharp completes 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 sharp as reported by npm 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

Most upvoted comments

Facing same issue on Vercel. Confirmed that my Vercel and local env are running node version = 18.17.1

I have already install sharp by npm install --force @img/sharp-linux-x64 When 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:

⨯ Error: Could not load the "sharp" module using the linux-x64 runtime
Possible solutions:
- Add platform-specific dependencies:
    npm install --os=linux --cpu=x64 sharp
  or
    npm install --force @img/sharp-linux-x64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/var/task/node_modules/sharp/lib/sharp.js:85:9)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at r.<computed>.e._load (/var/task/___vc/__launcher/__launcher.js:14:2299)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at w.require (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:11:25815)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:10:1) {
  page: '/api/og'
}

update: downgrade to 0.32.6 works (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/nft collects the corresponding sharp-darwin-arm64.node file 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.

Error: Could not load the "sharp" module using the darwin-x64 runtime
Possible solutions:
- Add platform-specific dependencies:
    npm install --os=darwin --cpu=x64 sharp
  or
    npm install --force @img/sharp-darwin-x64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install

@JClackett I think Vercel uses @vercel/nft under 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.6 and 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).

As a quick fix for now you could install an older version of sharp manually in your app. I tried with sharp@0.32.6 and it should remove the error from Vercel.

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=optional fixed 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 sharp automatically installed @img/sharp-linux-x64 and the error went away.

Please use either https://vercel.com/help#issues or https://github.com/orgs/vercel/discussions to report issues directly to Vercel.

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.