payloadcms / payloadcms/payload

Build errors on Cloudflare

Open
#16,646 1 comment 1 reaction 1 assignee View on GitHub

@nathanlentz is already working on this.

Since Jul 27, 2026.

area: core stale v3
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

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
  1. Clone the repo
  2. pnpm install
  3. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.