diff --git a/.changeset/lemon-zoos-chew.md b/.changeset/lemon-zoos-chew.md new file mode 100644 index 00000000..39157198 --- /dev/null +++ b/.changeset/lemon-zoos-chew.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +Add support for specifying wrangler environment when using next dev so that bindings and vars are properly loaded. This can be specified with the env variable NEXT_DEV_WRANGLER_ENV. diff --git a/packages/cloudflare/src/api/get-cloudflare-context.ts b/packages/cloudflare/src/api/get-cloudflare-context.ts index 9cbb4c91..1e627309 100644 --- a/packages/cloudflare/src/api/get-cloudflare-context.ts +++ b/packages/cloudflare/src/api/get-cloudflare-context.ts @@ -71,7 +71,10 @@ async function getCloudflareContextInNextDev< const { getPlatformProxy } = await import( /* webpackIgnore: true */ `${"__wrangler".replaceAll("_", "")}` ); - const { env, cf, ctx } = await getPlatformProxy(); + const { env, cf, ctx } = await getPlatformProxy({ + // This allows the selection of a wrangler environment while running in next dev mode + environment: process.env.NEXT_DEV_WRANGLER_ENV, + }); global[cloudflareContextInNextDevSymbol] = { env, cf: cf as unknown as CfProperties,