fix(templates): make with-cloudflare-d1 build with published npm packages#17393
Open
SybyAbraham wants to merge 1 commit into
Open
fix(templates): make with-cloudflare-d1 build with published npm packages#17393SybyAbraham 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.
|
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.