Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suppress invalid env variables on process.env in the next-dev submodule #737

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/fluffy-mayflies-switch.md
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions internal-packages/next-dev/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading