From cbe7cec205eb545d1e90379a66599e7b05f50a8a Mon Sep 17 00:00:00 2001 From: nickhaubner <36165177+nickhaubner@users.noreply.github.com> Date: Sat, 16 May 2026 15:27:16 -0400 Subject: [PATCH] fix(templates): guard realpath() return in with-cloudflare-d1 isCLI check On Cloudflare Workers, process.argv entries don't correspond to real files, so realpath() returns undefined and the subsequent .endsWith() call throws a TypeError on every request. Add optional chaining to skip non-existent paths when detecting the payload CLI. --- templates/with-cloudflare-d1/src/payload.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/with-cloudflare-d1/src/payload.config.ts b/templates/with-cloudflare-d1/src/payload.config.ts index da3d5fef44a..d0b30d36a7b 100644 --- a/templates/with-cloudflare-d1/src/payload.config.ts +++ b/templates/with-cloudflare-d1/src/payload.config.ts @@ -15,7 +15,7 @@ const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) const realpath = (value: string) => (fs.existsSync(value) ? fs.realpathSync(value) : undefined) -const isCLI = process.argv.some((value) => realpath(value).endsWith(path.join('payload', 'bin.js'))) +const isCLI = process.argv.some((value) => realpath(value)?.endsWith(path.join('payload', 'bin.js'))) const isProduction = process.env.NODE_ENV === 'production' const createLog =