withPayload in next config causes turbopack to always be used
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
- Create a new payload project with pnpm
- Run
pnpm run dev - See
turboin 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
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…?
Still an issue with v3.35.1.
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