next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Cannot find module 'sharp'

Open testerez opened this issue 1 year ago • 5 comments

Link to the code that reproduces this issue

https://github.com/testerez/test-next-sharp-import-error

To Reproduce

  1. deploy the project to Vercel
  2. open deployed app and notice that the image is not loading
  3. check Vercel Logs to see the error.

Current vs. Expected behavior

I already had a similar issue reported here: https://github.com/vercel/next.js/issues/56607# That was fixed but I'm now having the same issue again when updating sharp from 0.32.6 to 0.33.0. The issue happens only once the app is deployed to Vercel: https://test-next-sharp-import-error-bifv4sp30-testerez.vercel.app/

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: 8.12.0
Relevant Packages:
  next: 14.0.4
  eslint-config-next: 14.0.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

No response

testerez avatar Dec 12 '23 03:12 testerez

want to contribute

aniruddhapw avatar Dec 12 '23 07:12 aniruddhapw

Can confirm this is happening for us, too, and causes issues with ISR (though not on every page). Downgrading sharp to 0.32.6 fixes the issue.

Our overall issue must have something to do with next/image, because we didn't have sharp installed but were seeing issues with ISR. A little digging pointed me to a similar issue to this, so we installed the latest version of sharp but saw no improvement in our problem. Downgrading finally fixed it.

leffot avatar Dec 20 '23 11:12 leffot

Can confirm on v14.1. Running a standalone build in prod. Getting:

Error: 'sharp' is required to be installed [..]

No error after downgrading sharp to the above recommended version 0.32.6

linus-ha avatar Jan 28 '24 02:01 linus-ha

Likewise, after upgrading sharp to 0.33.2 this morning we got warnings in our logs:

Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly. Read more at: https://nextjs.org/docs/messages/sharp-missing-in-production

Following those docs didn't solve the issue. Adding the path to the sharp package in node_modules to our ENV didn't fix.

Have reverted to 0.32.6 for now.

JRhodes95 avatar Jan 29 '24 16:01 JRhodes95

I'm having the same issue 0.32.6 working all right but 0.33.2 is giving me this error

luluhoc avatar Jan 30 '24 12:01 luluhoc

Works on 0.32.6. We tested 0.33.0 and had the same issue

Linkinlog avatar Feb 13 '24 15:02 Linkinlog

This might be related: https://github.com/lovell/sharp/issues/3994 When using yarn 1, --ignore-engines is required. I could reproduce the original issue by installing just sharp in an empty project, starting Node REPL and try to require("sharp"). Without --ignore-engines it throws an error, with the flag, it works.

mvarendorff2 avatar Feb 20 '24 08:02 mvarendorff2

For people using an old version of Sharp, can you try it again?

The Vercel team have fixed stuff that were preventing newer versions of sharp from working.

I just deployed a project using [email protected] and it worked fine.

Kikobeats avatar Mar 05 '24 18:03 Kikobeats

This issue is that your repo has both yarn.lock and package-lock.json so yarn will be used. Since sharp dropped support for yarn@1, its expected to fail.

If you delete yarn.lock and update to [email protected] or newer, it will work.

styfle avatar Mar 05 '24 19:03 styfle

I use only pnpm-lock.yaml and have the same issue with the official dockerfile https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile

rusakovic avatar Mar 05 '24 22:03 rusakovic

@rusakovic There was another issue with pnpm specifically that was fixed in next@canary so please give that a try.

styfle avatar Mar 05 '24 22:03 styfle

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Mar 20 '24 00:03 github-actions[bot]