lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
28.91k stars 1.29k forks source link

Sharp is present in node_modules but still got error in server logs. Error: 'sharp' is required to be installed in standalone mode. #4189

Open waqas-nr opened 1 month ago

waqas-nr commented 1 month ago

Possible install-time or require-time problem

You must confirm both of these before continuing.

Are you using the latest version of sharp?

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.

Are you using a supported runtime?

If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue.

Are you using a supported package manager and installing optional dependencies?

If you cannot confirm any of these, please upgrade to the latest version of your chosen package manager and ensure you are allowing the installation of optional or multi-platform dependencies before opening an issue.

What is the complete error message, including the full stack trace?

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

What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory?

npm verb cli /home/dev/.nvm/versions/node/v20.10.0/bin/node /home/dev/.nvm/versions/node/v20.10.0/bin/npm npm info using npm@10.2.3 npm info using node@v20.10.0 npm verb title npm install sharp npm verb argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp" npm verb logfile logs-max:10 dir:/home/dev/.npm/_logs/2024-08-12T10_13_47_822Z- npm verb logfile /home/dev/.npm/_logs/2024-08-12T10_13_47_822Z-debug-0.log npm http fetch GET 200 https://registry.npmjs.org/sharp 3084ms (cache updated) npm http fetch GET 200 https://registry.npmjs.org/semver 286ms (cache updated) npm http fetch GET 200 https://registry.npmjs.org/detect-libc 329ms (cache updated) npm http fetch GET 200 https://registry.npmjs.org/color 559ms (cache updated) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-x64 607ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-arm64 733ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-x64 739ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-arm64 760ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-x64 792ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-x64 807ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-x64 1030ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-s390x 1210ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-s390x 1324ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-arm64 1362ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-x64 1482ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-ia32 1482ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-wasm32 1680ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm 1681ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm 1901ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-arm64 1997ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-x64 2050ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm64 2478ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm64 2983ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/color-convert 154ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/color-string 177ms (cache updated) npm http fetch GET 200 https://registry.npmjs.org/@emnapi%2fruntime 584ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/tslib 285ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/color-name 103ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/simple-swizzle 114ms (cache updated) npm http fetch GET 200 https://registry.npmjs.org/color-name 194ms (cache revalidated) npm http fetch GET 200 https://registry.npmjs.org/is-arrayish 101ms (cache revalidated) npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-win32-x64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-win32-ia32 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-wasm32 npm verb reify failed optional dependency /home/dev/node_modules/@emnapi/runtime npm verb reify failed optional dependency /home/dev/node_modules/tslib npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-linuxmusl-arm64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-linux-s390x npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-linux-arm64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-linux-arm npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-libvips-linuxmusl-arm64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-libvips-linux-s390x npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-libvips-linux-arm64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-libvips-linux-arm npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-libvips-darwin-x64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-libvips-darwin-arm64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-darwin-x64 npm verb reify failed optional dependency /home/dev/node_modules/@img/sharp-darwin-arm64 npm http fetch GET 200 https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz 206ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-7.6.3.tgz 391ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz 394ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.4.tgz 628ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.4.tgz 1004ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/sharp/-/sharp-0.33.4.tgz 1345ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.2.tgz 1545ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.2.tgz 18027ms (cache miss) npm info run sharp@0.33.4 install node_modules/sharp node install/check

sharp@0.33.4 install node install/check

npm info run sharp@0.33.4 install { code: 0, signal: null }

added 13 packages in 26s

5 packages are looking for funding run npm fund for details npm verb exit 0 npm info ok

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System: OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa) CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics Memory: 5.90 GB / 15.48 GB Container: Yes Shell: 5.0.17 - /bin/bash Binaries: Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node Yarn: 4.4.0 - ~/.nvm/versions/node/v20.10.0/bin/yarn npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm npmPackages: sharp: 0.33.4 => 0.33.4

Description

Docker container -> Node 20.alpine Node version -> 20.10.0 Yarn Version -> 4.4.0 Next.js version -> 13.5.6 React Version -> 18.3.1 Sharp Version -> 0.33.4

I have upgraded my Yarn version as described in these resources:

https://github.com/lovell/sharp/issues/3951 https://sharp.pixelplumbing.com/install

I have also set NEXT_SHARP_PATH=node_modules/sharp as mentioned in this link https://nextjs.org/docs/messages/sharp-missing-in-production. I can confirm that the Sharp package is present in node_modules, but I am still getting the error.

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

@lovell @leon Can you help me to fix this issue?

lovell commented 1 month ago

Next.js version -> 13.5.6

There have been a few bugs in Next.js relating to its standalone mode, please upgrade to the latest version.

waqas-nr commented 1 month ago

@lovell thanks for your quick reply. I will upgrade the Next.js version and let you know.

waqas-nr commented 1 month ago

I still have the same issue after upgrading next.js to 14.2.5

FinzyPHINZY commented 4 weeks ago

I still have the same issue after upgrading next.js to 14.2.5

Same here also. It's a mess.

lovell commented 4 weeks ago

I'm sorry to hear that you think this is a mess. The most constructive thing anyone can do is to provide a sample repository with minimal dependencies that allows someone else to reproduce.

FinzyPHINZY commented 3 weeks ago

Sorry about my language. I was just highly frustrated. My bad. I'll provide the repo in a few hours

sfratini commented 3 weeks ago

I have this same issue with 0.33.5. I had to roll back to 0.33.4. Latest version is not installing the libraries inside @img folder, it gets generated empty.
I had my package,json as "^0.33.4" so I fixed it by putting it as a fixed version of 0.33.4.

My case is that I am building for linux and x64 in a macos agent like "npm install --verbose --os=linux --cpu=x64 sharp"

Edit: It might not actually be the same issue but this bug was reported 2 weeks ago, the last time our CI ran correctly was also 2 weeks ago and that is when the 0.33.5 was released. I think there is something specific about this release.

lovell commented 3 weeks ago

My case is that I am building for linux and x64 in a macos agent like "npm install...

Watch out for the infamous npm cross-platform lockfile bug https://github.com/npm/cli/issues/4828 as documented at https://sharp.pixelplumbing.com/install#cross-platform

KimCookieYa commented 4 days ago

I have this same issue with 0.33.5. I had to roll back to 0.33.4. Latest version is not installing the libraries inside @img folder, it gets generated empty. I had my package,json as "^0.33.4" so I fixed it by putting it as a fixed version of 0.33.4.

My case is that I am building for linux and x64 in a macos agent like "npm install --verbose --os=linux --cpu=x64 sharp"

Edit: It might not actually be the same issue but this bug was reported 2 weeks ago, the last time our CI ran correctly was also 2 weeks ago and that is when the 0.33.5 was released. I think there is something specific about this release.

Thanks to you, I solved it.

sfratini commented 3 days ago

My case is that I am building for linux and x64 in a macos agent like "npm install...

Watch out for the infamous npm cross-platform lockfile bug npm/cli#4828 as documented at https://sharp.pixelplumbing.com/install#cross-platform

Sorry for late reply. I checked it out but I don't think that is the issue. We are doing a clean install and as I said before, I can easily reproduce this with 0.33.5, however 0.33.4 works fine. The generated build folder has all the img folder empty so no libraries are getting downloaded.

lovell commented 2 days ago

My case is that I am building for linux and x64 in a macos agent like "npm install --verbose --os=linux --cpu=x64 sharp"

Did you try adding the relevant libc value for your choice of Linux, which is a requirement of the npm package manager? Please also ensure you're using the latest version of npm as there have been bugs in older versions relating to cross-platform installations.

https://sharp.pixelplumbing.com/install#cross-platform

When the cross-target is Linux, the C standard library must be specified.

npm install --cpu=x64 --os=linux --libc=glibc sharp
npm install --cpu=x64 --os=linux --libc=musl sharp

If anyone is still having problems, please provide a complete, minimal sample repo that allows someone else to reproduce.