Skip to content

Commit edf22de

Browse files
ceccecclaude
andcommitted
fix(build): patch payload loadEnv for OpenNext's @next/env shim
OpenNext worker bundling (esbuild) failed with: No matching export in shims/env.js for import "default" (payload/dist/bin/loadEnv.js) loadEnv does `import x from '@next/env'` (a default import — correct for the real CJS package), but OpenNext replaces @next/env with an ESM shim exposing only a named `loadEnvConfig` (no default). loadEnv is pulled into the worker bundle via payload/node yet never runs at worker runtime. pnpm-patch it to a namespace import with a default fallback (`nextEnvImport.loadEnvConfig ?? nextEnvImport.default?. loadEnvConfig`), which resolves against both the ESM shim and the real CJS package. With this, the full `opennextjs-cloudflare build` completes locally against the real D1/R2 (remote bindings) — .open-next/worker.js saved. Remove this patch once the Payload/OpenNext @next/env interop is fixed upstream. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0aa4cc6 commit edf22de

3 files changed

Lines changed: 103 additions & 82 deletions

File tree

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@
169169
"overrides": {
170170
"formdata-node": "6.0.3",
171171
"preact": ">=10.28.2"
172+
},
173+
"patchedDependencies": {
174+
"payload@4.0.0-canary.1": "patches/payload@4.0.0-canary.1.patch"
172175
}
173176
},
174177
"packageManager": "pnpm@10.33.2",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/dist/bin/loadEnv.js b/dist/bin/loadEnv.js
2+
index b61ecc1684f0b686fa8bbcefa68b5ed825c09420..a7eca40e1d7ca727cb103fdb26361139b8113e2d 100644
3+
--- a/dist/bin/loadEnv.js
4+
+++ b/dist/bin/loadEnv.js
5+
@@ -1,6 +1,6 @@
6+
-import nextEnvImport from '@next/env';
7+
+import * as nextEnvImport from '@next/env';
8+
import { findUpSync } from '../utilities/findUp.js';
9+
-const { loadEnvConfig } = nextEnvImport;
10+
+const loadEnvConfig = nextEnvImport.loadEnvConfig ?? nextEnvImport.default?.loadEnvConfig;
11+
/**
12+
* Try to find user's env files and load it. Uses the same algorithm next.js uses to parse env files, meaning this also supports .env.local, .env.development, .env.production, etc.
13+
*/ export function loadEnv(path) {

0 commit comments

Comments
 (0)