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

Cannot find module 'sharp' #59516

Closed
1 task done
testerez opened this issue Dec 12, 2023 · 12 comments
Closed
1 task done

Cannot find module 'sharp' #59516

testerez opened this issue Dec 12, 2023 · 12 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@testerez
Copy link

testerez commented Dec 12, 2023

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: #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

  • 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 testerez added the bug Issue was opened via the bug report template. label Dec 12, 2023
@aniruddhapw
Copy link

want to contribute

@leffot
Copy link

leffot commented Dec 20, 2023

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.

@linus-ha
Copy link

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

@JRhodes95
Copy link

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.

@luluhoc
Copy link

luluhoc commented Jan 30, 2024

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

@Linkinlog
Copy link

Linkinlog commented Feb 13, 2024

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

@mvarendorff2
Copy link

This might be related: lovell/sharp#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.

@Kikobeats
Copy link
Member

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.

@styfle
Copy link
Member

styfle commented Mar 5, 2024

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 styfle closed this as completed Mar 5, 2024
@rusakovic
Copy link

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

@styfle
Copy link
Member

styfle commented Mar 5, 2024

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

Copy link
Contributor

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests