fix(web): skip payload withPayload in production build
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

Payload CMS v3.81 withPayload() injects a turbopack config key
that Next.js 16.0.10 rejects in production builds (needs >=16.1).
Load withPayload only in dev; production gets a pass-through.

Payload admin works locally; production serves blog/changelog
as regular Next.js pages querying the Payload API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-06 00:56:08 +01:00
parent 5c4cb2cf84
commit 6b062ab239

View File

@@ -1,8 +1,17 @@
import type { NextConfig } from "next";
import { withPayload } from "@payloadcms/next/withPayload";
import env from "./env.config";
// Payload CMS requires Next.js >=16.1.0 for production builds (turbopack).
// Until we upgrade from 16.0.10, load withPayload only in dev where
// turbopack isn't used for builds. Production serves blog/changelog
// as static pages — Payload admin is dev-only for now.
const withPayload =
process.env.NODE_ENV === "production"
? (c: NextConfig) => c
: // eslint-disable-next-line @typescript-eslint/no-require-imports
require("@payloadcms/next/withPayload").withPayload;
const INTERNAL_PACKAGES = [
"@turbostarter/analytics-web",
"@turbostarter/api",
@@ -116,4 +125,4 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: env.ANALYZE,
});
export default withPayload(withBundleAnalyzer(config));
export default withPayload(withBundleAnalyzer(config)) as NextConfig;