diff --git a/.changeset/fluffy-mayflies-switch.md b/.changeset/fluffy-mayflies-switch.md new file mode 100644 index 000000000..41ac6a7d9 --- /dev/null +++ b/.changeset/fluffy-mayflies-switch.md @@ -0,0 +1,9 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +suppress invalid env variables on `process.env` in the `next-dev` submodule + +improve `setupDevPlatform` so that it suppresses the environment variables (present +in the edge runtime) that the Next.js dev server sets on `process.env` (such should not +be used anyways since they won't be available in the preview nor in the deployed app) diff --git a/internal-packages/next-dev/src/shared.ts b/internal-packages/next-dev/src/shared.ts index 46c6b0ec4..192073ea1 100644 --- a/internal-packages/next-dev/src/shared.ts +++ b/internal-packages/next-dev/src/shared.ts @@ -60,6 +60,12 @@ function monkeyPatchProcessEnv( !runtimeContext.process.env[processEnvIsPatched] ) { if (runtimeContext.process.env) { + for (const key of Object.keys(runtimeContext.process.env)) { + if (!(key in env)) { + delete runtimeContext.process.env[key]; + } + } + for (const [name, binding] of Object.entries(env)) { runtimeContext.process.env[name] = binding; }