next.js
next.js copied to clipboard
Cannot find module 'sharp'
Link to the code that reproduces this issue
https://github.com/testerez/test-next-sharp-import-error
To Reproduce
- deploy the project to Vercel
- open deployed app and notice that the image is not loading
- 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
want to contribute
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.
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
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.
I'm having the same issue 0.32.6
working all right but 0.33.2
is giving me this error
Works on 0.32.6
. We tested 0.33.0
and had the same issue
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.
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.
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.
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 There was another issue with pnpm specifically that was fixed in next@canary
so please give that a try.
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.