Describe the Bug
A follow-up on #15002:
When importing Payload for using the Local API on Cloudflare's worker platform, builds fail with:
✘ [ERROR] No matching export in
"node_modules/.pnpm/file-type@21.3.4/node_modules/file-type/core.js" for import
"fileTypeFromFile"
node_modules/.pnpm/payload@4.0.0-internal.38b7f1d_graphql@16.14.0_typescript@5.9.3/node_modules/payload/dist/uploads/checkFileRestrictions.js:1:29:
1 │ import { fileTypeFromBuffer, fileTypeFromFile } from 'file-type';
Since file-type probably won't be used by the Local API, I patched file-type using pnpm patch:
diff --git a/core.js b/core.js
index 1a28e8b413f594a9f28353851d47fef908d70df3..828f7d7e7ed6cdb419e17d07ef284b29edb131c2 100644
--- a/core.js
+++ b/core.js
@@ -390,6 +390,10 @@ function createByteLimitedReadableStream(stream, maximumBytes) {
});
}
+export async function fileTypeFromFile(path, options) {
+ throw new Error('The `fileTypeFromFile` function is not supported in this environment');
+}
+
export async function fileTypeFromStream(stream, options) {
return new FileTypeParser(options).fromStream(stream);
}
However, the next error is then already waiting:
Uncaught Error: No such module "node:tty".
imported from "index.js"
I tried it with a SvelteKit app bundled by vite, but could also reproduce it using a bare Cloudflare worker file. Both, with payload v3 and v4.
Interestingly, the fully-fledged Payload Cloudflare D1 example seems to work. I couldn't make out the difference. The wrangler.jsonc config isn't it.
Link to the code that reproduces this issue
https://github.com/stephtr/payload-cloudflare-worker
Reproduction Steps
- Clone the repo
pnpm install
pnpm dev
Which area(s) are affected?
area: core
Environment Info
Binaries:
Node: 26.1.0
npm: 11.13.0
Yarn: N/A
pnpm: 11.1.1
Relevant Packages:
payload: 4.0.0-internal.38b7f1d
@payloadcms/db-d1-sqlite: 3.84.1
@payloadcms/drizzle: 3.84.1
@payloadcms/translations: 4.0.0-internal.38b7f1d
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:55 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6031
Available memory (MB): 36864
Available CPU cores: 14
Describe the Bug
A follow-up on #15002:
When importing Payload for using the Local API on Cloudflare's worker platform, builds fail with:
Since
file-typeprobably won't be used by the Local API, I patchedfile-typeusingpnpm patch:However, the next error is then already waiting:
I tried it with a SvelteKit app bundled by vite, but could also reproduce it using a bare Cloudflare worker file. Both, with payload v3 and v4.
Interestingly, the fully-fledged Payload Cloudflare D1 example seems to work. I couldn't make out the difference. The
wrangler.jsoncconfig isn't it.Link to the code that reproduces this issue
https://github.com/stephtr/payload-cloudflare-worker
Reproduction Steps
pnpm installpnpm devWhich area(s) are affected?
area: core
Environment Info