payload icon indicating copy to clipboard operation
payload copied to clipboard

withPayload in next config causes turbopack to always be used

Open MakoriSM opened this issue 11 months ago • 2 comments

Describe the Bug

When trying to debug my payload application I wanted to connect my app to the vscode debugger, this is seemingly not possible with turbopack enabled but when I went to remove it from config I realised no matter what I did turbopack was enabled. After a lot of trial and error I figured out that when the withPayload function wraps the next.config.ts output it always runs with turbopack. I was only able to fix it by writing the export like this:

const payloadConfig = withPayload(nextConfig)

payloadConfig.experimental!.turbo = undefined
export default payloadConfig

Looking at the docs this isn't mentioned anywhere to be intended behaviour nor are we given any clear way to turn it off

Link to the code that reproduces this issue

https://github.com/MakoriSM/with-payload-turbopack

Reproduction Steps

  1. Create a new payload project with pnpm
  2. Run pnpm run dev
  3. See turbo in the Experiments

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

Not sure

Environment Info

Binaries:
  Node: 20.13.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.21.0
  next: 15.1.5
  @payloadcms/db-mongodb: 3.21.0
  @payloadcms/email-nodemailer: 3.21.0
  @payloadcms/graphql: 3.21.0
  @payloadcms/next/utilities: 3.21.0
  @payloadcms/payload-cloud: 3.21.0
  @payloadcms/richtext-lexical: 3.21.0
  @payloadcms/translations: 3.21.0
  @payloadcms/ui/shared: 3.21.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 32694
  Available CPU cores: 16

MakoriSM avatar Feb 06 '25 17:02 MakoriSM

I don't know whether this is related, but I noticed that production Payload builds seem to be using Turbopack although I haven't specifically enabled it in my next.config.js:

$ pnpm build

   ▲ Next.js 15.1.7
   - Experiments (use with caution):
     · turbo

   Creating an optimized production build ...

withPayload() seems to enable Turbopack nevertheless, because the final next.config.js always includes this:

{
  "experimental": {
    "turbo": {
      "resolveAlias": {
        "payload-mock-package": "payload-mock-package"
      }
    }
  }
}

and probably the pure existence of the experimental.turbo key already enables Turbopack which, as far as I know, is not ready for production builds…?

soulchild avatar Feb 27 '25 07:02 soulchild

Still an issue with v3.35.1.

atlasgong avatar Apr 22 '25 07:04 atlasgong

This does not reproduce after upgrading Next.js & Payload

> pnpm dev

> [email protected] dev /workspaces/with-payload-turbopack
> cross-env NODE_OPTIONS=--no-deprecation next dev

   ▲ Next.js 15.3.4
   - Local:        http://localhost:3000
   - Network:      http://10.0.13.235:3000

 ✓ Starting...
 ✓ Ready in 1642ms
Binaries:
  Node: 22.16.0
  npm: 9.8.1
  Yarn: 1.22.22
  pnpm: 10.11.0
Relevant Packages:
  payload: 3.44.0
  next: 15.3.4
  @payloadcms/db-mongodb: 3.44.0
  @payloadcms/email-nodemailer: 3.44.0
  @payloadcms/graphql: 3.44.0
  @payloadcms/next/utilities: 3.44.0
  @payloadcms/payload-cloud: 3.44.0
  @payloadcms/richtext-lexical: 3.44.0
  @payloadcms/translations: 3.44.0
  @payloadcms/ui/shared: 3.44.0
  react: 19.0.0
  react-dom: 19.0.0

jaens avatar Jul 01 '25 12:07 jaens