Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/modern-yaks-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

fix: process.env has a higher loading priority than .env files
3 changes: 2 additions & 1 deletion examples/playground14/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TEST_ENV_VAR=TEST_VALUE
TEST_ENV_VAR=TEST_VALUE
PROCESS_ENV_VAR=.ENV_FILE
5 changes: 5 additions & 0 deletions examples/playground14/e2e/cloudflare.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ test.describe("playground/cloudflare", () => {
const { nextConfig } = await res.json();
expect(nextConfig.output).toEqual("standalone");
});

test("Environment variable defined on process.env are not overridden by .env files", async ({ page }) => {
const res = await page.request.get("/api/env");
await expect(res.json()).resolves.toEqual(expect.objectContaining({ PROCESS_ENV_VAR: "process.env" }));
});
});
3 changes: 2 additions & 1 deletion examples/playground14/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
],
"vars": {
"hello": "Hello World from the cloudflare context!"
"hello": "Hello World from the cloudflare context!",
"PROCESS_ENV_VAR": "process.env"
}
}
2 changes: 1 addition & 1 deletion packages/cloudflare/src/cli/templates/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function populateProcessEnv(url: URL, env: CloudflareEnv) {
const mode = env.NEXTJS_ENV ?? "production";
if (nextEnvVars[mode]) {
for (const key in nextEnvVars[mode]) {
process.env[key] = nextEnvVars[mode][key];
process.env[key] ??= nextEnvVars[mode][key];
}
}

Expand Down