next.js: Standalone export Sharp executable is not present with pnpm

Link to the code that reproduces this issue

https://github.com/limanmys/website/blob/7e9d2c005e7d3197c8aecbfc98fa458a4ee40252/.github/workflows/main.yml#L45

To Reproduce

  1. Set output to standalone on next.config.ts
  2. npm run build
  3. Move to standalone folder to external source for using
  4. node server.js
  5. Get “Error: ‘sharp’ is required to be installed in standalone mode for the image optimization to function correctly.”
  6. Move @img folder from project path node_modules to .next/standalone/node_modules
  7. Problem solved

Current vs. Expected behavior

When i build and use export, i get “Error: ‘sharp’ is required to be installed in standalone mode for the image optimization to function correctly.” error. I fixed it by myself at https://github.com/limanmys/website/blob/7e9d2c005e7d3197c8aecbfc98fa458a4ee40252/.github/workflows/main.yml#L45 but isn’t it supposed to move node_modules/@img folder to .next/standalone/node_modules?

Expected behavior is .next/standalone/node_modules folder to contain @img folder for Sharp after exporting but at this time it is not.

Verify canary release

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

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023
Binaries:
  Node: 18.19.0
  npm: 10.2.3
  Yarn: 3.3.0
  pnpm: 8.10.2
Relevant Packages:
  next: 14.0.3
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: standalone

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

Standalone mode (output: “standalone”)

Additional context

I also tested latest 14.0.4-canary.47 version still happens.

I am deploying to Ubuntu 22.04 with standalone export.

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 10
  • Comments: 18 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Try using version 0.32.6 of Sharp

Same here. Deploying with Docker + DigitalOcean App Platform. Docker configs based on official examples have the same error.

https://github.com/limanmys/website/blob/7e9d2c005e7d3197c8aecbfc98fa458a4ee40252/.github/workflows/main.yml#L45

@rusted-love I fixed it temporarily with this way.

Same here. Deploying with Docker + DigitalOcean App Platform. Docker configs based on official examples have the same error.

Looks like the issue in this case was pnpm has slightly different node_modules behavior than npm so some of the relevant binary files were not copied correctly.

This will be fixed in https://github.com/vercel/next.js/pull/61538 thanks!

finally found that issue here 🙏 any ETA to get the issue resolved? I assume a lot of people running in standalone mode will face this issue 😅

It should already be fixed in v14.0.5-canary.36

Same in standalone mode, I had to revert to 0.32.6