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

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

Closed
5 of 11 tasks
waqas-nr opened this issue Aug 12, 2024 · 12 comments

Comments

@waqas-nr
Copy link

waqas-nr commented Aug 12, 2024

Possible install-time or require-time problem

You must confirm both of these before continuing.

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.

Are you using a supported runtime?

  • I am using Node.js with a version that satisfies ^18.17.0 || ^20.3.0 || >=21.0.0
  • I am using Deno
  • I am using Bun

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?

  • I am using npm >= 10.1.0 with --include=optional
  • I am using yarn >= 3.2.0
  • I am using pnpm >= 7.1.0 with --no-optional=false
  • I am using Deno
  • I am using Bun

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 [email protected]
npm info using [email protected]
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 [email protected] install node_modules/sharp node install/check

[email protected] install
node install/check

npm info run [email protected] 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:

#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
Copy link
Owner

lovell commented Aug 12, 2024

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
Copy link
Author

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

@waqas-nr
Copy link
Author

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

@FinzyPHINZY
Copy link

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

Same here also. It's a mess.

@lovell
Copy link
Owner

lovell commented Aug 20, 2024

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
Copy link

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

@sfratini
Copy link

sfratini commented Aug 27, 2024

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
Copy link
Owner

lovell commented Aug 27, 2024

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

@KimCookieYa
Copy link

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
Copy link

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
Copy link
Owner

lovell commented Sep 15, 2024

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.

@lovell
Copy link
Owner

lovell commented Oct 15, 2024

There's been no update on this issue for a month and no-one has provided a sample repo that allows someone else to reproduce so I'm going to close it. @waqas-nr Please feel free to re-open with the requested information if you still require help.

@lovell lovell closed this as completed Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants