Skip to content

Issue with sharp optional peer dependency with Payload admin introduced since canary.7 #65247

@paulpopus

Description

@paulpopus

Link to the code that reproduces this issue

https://github.com/paulpopus/nextjs-payload-sharp-issue

To Reproduce

Ensure that you have .env available with the database and payload secret configured, you will need a mongo db running for which you can use a remote DB or the provided docker compose file

DATABASE_URI=mongodb://127.0.0.1/fresh-payload
PAYLOAD_SECRET=f4cd94b2c27475da3466ca44

Then run yarn dev and try to access localhost:3000/admin.

When running nextjs canary version 7 it will work, however newer version of canary have introduced an optional sharp dependency that does not resolve correctly with these package managers and will not work.

So to be clear, change the package.json dependency to canary.34 for next and it will break after installing dependencies again.

I see this issue happen with yarn v1 and pnpm v8 equally

Current vs. Expected behavior

Current
When accessing /admin I see a sharp missing error

Error: Could not load the "sharp" module using the linux-x64 runtime

Expected
When accessing /admin I expect the admin panel to work

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #202403110203~1714077665~22.04~4c8e9a0 SMP PREEMPT_DYNAMIC Thu A
  Available memory (MB): 31782
  Available CPU cores: 20
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.21
  pnpm: 8.15.8
Relevant Packages:
  next: 14.3.0-canary.7 // There is a newer canary version (14.3.0-canary.34) available, please upgrade! 
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

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

Module Resolution, Runtime

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

next dev (local)

Additional context

"next": "14.3.0-canary.7" works
"next": "14.3.0-canary.34" does not work

canary.7 did not have sharp listed as a dependency and one of the versions since then has introduced it

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module ResolutionModule resolution (CJS / ESM, module resolving).RuntimeRelated to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions