Repository navigation
fix(templates): make with-cloudflare-d1 build with published npm packages - #17393
Closed
SybyAbraham wants to merge 1 commit into
Closed
SybyAbraham wants to merge 1 commit into
SybyAbraham wants to merge 1 commit into
Conversation
…ages The with-cloudflare-d1 template on main references several APIs that have not been published to npm, making it impossible to build when installed standalone via create-payload-app: 1. payload build (build script) - not available in any published payload CLI version. Changed to next build. 2. Config.storage (payload.config.ts) - unreleased API not in any published @payloadcms/* package. Changed to plugins, which has always existed. (A codemod migrate-storage-adapters-to-config exists upstream for this transition.) 3. generatePayloadViewport (layout.tsx) - unreleased export not in any published @payloadcms/next version. Changed to metadata, which has always been exported. (A codemod migrate-next-generate-viewport-export exists upstream.) 4. Missing CSS/SCSS type declarations - the monorepo provides these via tools/assets.d.ts (wired through tsconfig.base.json), but standalone templates lack this file. Added src/assets.d.ts with the same declarations. 5. isCLI detection - switching from payload build to next build means payload/bin.js is no longer in process.argv, so isCLI was always false during build. This caused the config to use getCloudflareContext() (production path requiring CLOUDFLARE_API_TOKEN) instead of getCloudflareContextFromWrangler() (local wrangler path). Extended isCLI to also detect next/dist/bin/next. 6. realpath crash - the realpath() helper returned undefined when fs.existsSync() is false (the case for every process.argv entry in the Workers runtime), and the subsequent .endsWith() call on undefined threw. Wrapped in try/catch with a null guard. 7. remoteBindings during build - getCloudflareContextFromWrangler() was called with remoteBindings: isProduction, which during next build (NODE_ENV=production) tried to connect to real Cloudflare D1/R2 resources. Since this function is only called for CLI/build/dev (never production runtime), changed to remoteBindings: false. Also changed the D1 binding in wrangler.jsonc from remote: true to remote: false so the template builds out of the box without pre-configured Cloudflare resources. 8. engines.node - lowered from >=24.15.0 to >=22.0.0 for compatibility with Cloudflare Workers Builds (Node 22.16.0). Bumped @payloadcms/* dependencies from 3.82.1 to 3.86.0 (latest published). Verified with a clean next build: TypeScript compilation passes, all 7 routes generate successfully.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
nathanlentz
added a commit
that referenced
this pull request
Aug 3, 2026
…17577) ## Summary The `with-cloudflare-d1` template used older versions of Payload, Next.js, and related tooling than the other Next 16 templates. The build also defaulted to Turbopack, which is not compatible with the Cloudflare deployment pipeline due to some development tooling being present within the Payload database adapter. ## Why `@payloadcms/db-d1-sqlite` lists `drizzle-kit` as a normal dependency, not a dev dependency, because Payload needs it at runtime to generate and push D1 schema changes. Turbopack traces this dependency into the server bundle, and drizzle-kit pulls in a Node-only toolchain that is not compatible with the Cloudflare Workers runtime. That breaks the production build. There is no clean, non-breaking fix for this today. Moving `drizzle-kit` out of the adapter's dependencies, or splitting it into a separate optional package, would change the public contract of `@payloadcms/db-d1-sqlite` and of any code that relies on it for migrations. ## What Updated the `with-cloudflare-d1` template to Payload 3.86.0, Next 16.2.6, React 19.2.6, and matching versions of `@opennextjs/cloudflare`, `wrangler`, and related dependencies. This aligns the template with the other Next 16 templates. Changed the `build` script to run with the `--webpack` flag. This is the biggest workaround to fix One-Click deployments to Cloudflare in the short-term. ## Alternatives considered A shim package or a lazy-loading wrapper around the `drizzle-kit` require were considered as ways to keep the Turbopack build working. this feels pretty hacky though and I'm not in love with it as a solution. ## Related work - #16470 reports the root cause described above: `drizzle-kit/api` is reachable from the production module graph of `@payloadcms/db-sqlite` and `@payloadcms/db-d1-sqlite`, which breaks OpenNext Cloudflare bundling. This PR works around it for the template by forcing a webpack build; the underlying issue in the adapters is still open. - #17393 is a separate, broader fix for this template that also bumps it to Payload 3.86.0 and additionally fixes several breakages that surface when installing the template standalone via `create-payload-app` (build script, storage/plugins config, viewport export, CSS type declarations, and others). This PR is scoped only to the version bump and the webpack build fix. - #17195 (fixed by #17393) reports that the template's `storage` config key does not exist in released 3.x. That issue does not apply to this branch, since this template already uses the `plugins` config key.
Collaborator
|
The Cloudflare One Click deployment button on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
with-cloudflare-d1template onmainreferences several APIs that have not been published to npm. Anyone installing the template viacreate-payload-appgets TypeScript errors and a failed build.The root cause: the template is developed inside the monorepo where workspace packages have unreleased APIs. The CI (
post-release-templates.yml) only bumps lockfiles — it never runs a standalone build — so these breakages go undetected.Changes
1.
payload build→next build(package.json)payload buildis not available in any publishedpayloadCLI version. Changed the build script tonext build.2.
Config.storage→Config.plugins(payload.config.ts)storageis an unreleased API not in any published@payloadcms/*package. Changed toplugins, which has always existed. (A codemodmigrate-storage-adapters-to-configexists upstream for this transition.)This is the same fix proposed in #17217 and reported in #17195 — this PR includes it as part of a broader fix for the template.
3.
generatePayloadViewport→metadata(layout.tsx)generatePayloadViewportis an unreleased export not in any published@payloadcms/nextversion. Changed tometadata, which has always been exported. (A codemodmigrate-next-generate-viewport-exportexists upstream.)4. CSS/SCSS type declarations (
src/assets.d.ts— new)The monorepo provides
declare module '*.css'anddeclare module '*.scss'viatools/assets.d.ts(wired throughtsconfig.base.json). Standalone templates lack this file, causingTS2882on side-effect style imports. Addedsrc/assets.d.tswith the same declarations.5.
isCLIdetection fornext build(payload.config.ts)Switching from
payload buildtonext buildmeanspayload/bin.jsis no longer inprocess.argv, soisCLIwas alwaysfalseduring build. This caused the config to usegetCloudflareContext()(production path requiringCLOUDFLARE_API_TOKEN) instead ofgetCloudflareContextFromWrangler()(local wrangler path). ExtendedisCLIto also detectnext/dist/bin/next.6.
realpathcrash guard (payload.config.ts)The
realpath()helper returnedundefinedwhenfs.existsSync()is false — the case for everyprocess.argventry in the Workers runtime — and the subsequent.endsWith()call onundefinedthrew. Wrapped intry/catchwith a null guard. (Supersedes #17392 for this file.)7.
remoteBindingsduring build (payload.config.ts,wrangler.jsonc)getCloudflareContextFromWrangler()was called withremoteBindings: isProduction, which duringnext build(NODE_ENV=production) tried to connect to real Cloudflare D1/R2 resources. Since this function is only called for CLI/build/dev (never production runtime), changed toremoteBindings: false. Also changed the D1 binding inwrangler.jsoncfromremote: truetoremote: falseso the template builds out of the box without pre-configured Cloudflare resources.8.
engines.node(package.json)Lowered from
>=24.15.0to>=22.0.0for compatibility with Cloudflare Workers Builds (Node 22.16.0).9. Dependency bumps (
package.json)Bumped
@payloadcms/*packages from3.82.1to3.86.0(latest published).Verification
Cloned the template standalone, applied all changes, ran
pnpm install && pnpm run build:TypeScript compilation passes, all 7 routes generate successfully, no errors.
Relationship to existing issues and PRs
storageconfig key doesn't exist in released 3.x — R2 never applied and admin crashes with "Functions cannot be passed directly to Client Components" #17195 —storageconfig key doesn't exist in released 3.x (thestorage→pluginschange, item 2 above)chore(templates): fix with-cloudflare-d1 storage adapter registration(only fixes thestorage→pluginsissue; this PR covers that plus 8 additional breakages)fix(templates): guard realpath crash in with-cloudflare-d1 on Cloudflare Workers(therealpathguard is included here, item 6 above)with-cloudflare-d1 template is broken from v3.85.0(fixed in v3.85.2, but the template pins 3.82.1 which has the same class of problem)Notes
remote: trueinwrangler.jsoncand provide a realdatabase_id.