Skip to content

fix(cli): symlink .env.local to .dev.vars before preview#2944

Open
matthewvolk wants to merge 1 commit intoalphafrom
CATALYST-1826-start-cmd-dev-vars
Open

fix(cli): symlink .env.local to .dev.vars before preview#2944
matthewvolk wants to merge 1 commit intoalphafrom
CATALYST-1826-start-cmd-dev-vars

Conversation

@matthewvolk
Copy link
Contributor

Summary

  • Copy .env.local to .bigcommerce/.dev.vars before running opennextjs-cloudflare preview in the start command
  • Wrangler reads secrets from .dev.vars, not .env.local, and silently ignores symlinks
  • Warns (instead of erroring) if .env.local is missing, to avoid breaking CI flows

Test plan

  • Existing tests updated (copyFileSync mock added)
  • All 38 tests pass (pnpm test)
  • Manual: catalyst build && catalyst start with .env.local present — verify preview has env vars
  • Manual: catalyst start without .env.local — verify warning is logged

@matthewvolk matthewvolk requested a review from a team as a code owner March 20, 2026 20:09
@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
catalyst Ready Ready Preview, Comment Mar 20, 2026 9:52pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

⚠️ No Changeset found

Latest commit: 42a860f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +47 to +49
consola.start('Copying .env.local to .bigcommerce/.dev.vars...');
copyFileSync(envLocal, devVars);
consola.success('.dev.vars created');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought wrangler/opennext can now read from .env.local?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was my assumption but the only reason I opened this PR is because it wasn't working. If you're able to test it locally and it works for you, I've got no problem closing this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think CF is trying to move to .env.local instead of .dev.vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is legit. I just tested locally. Here's what happened.

running from core/

With core/.env.local, no env vars detected:

$ node ../packages/catalyst/dist/cli.js start
◢ @bigcommerce/catalyst v1.0.0-alpha.0                                                                                          4:14:46 PM


┌───────────────────────────────┐
│ OpenNext — Cloudflare preview │
└───────────────────────────────┘

Monorepo detected at /Users/matt.volk/code/work/catalyst-deploy

Populating R2 incremental cache...
Successfully populated cache with 25 assets
Tag cache does not need populating

 ⛅️ wrangler 4.76.0
───────────────────
Your Worker has access to the following bindings:
Binding                                                                           Resource            Mode
env.NEXT_CACHE_DO_QUEUE (DOQueueHandler)                                          Durable Object      local
env.NEXT_TAG_CACHE_DO_SHARDED (DOShardedTagCache)                                 Durable Object      local
env.NEXT_CACHE_DO_PURGE (BucketCachePurge)                                        Durable Object      local
env.NEXT_INC_CACHE_R2_BUCKET (project-accd0361-2470-11f1-875e-1e6bd38089e2)       R2 Bucket           local
env.WORKER_SELF_REFERENCE (project-accd0361-2470-11f1-875e-1e6bd38089e2)          Worker              local [connected]
env.ASSETS                                                                        Assets              local

Since the file must be relative to the wrangler config file, first copy .env.local to core/.bigcommerce/.env.local

$ cp .env.local .bigcommerce/.env.local
$ node ../packages/catalyst/dist/cli.js start
◢ @bigcommerce/catalyst v1.0.0-alpha.0                                                                                          4:14:46 PM


┌───────────────────────────────┐
│ OpenNext — Cloudflare preview │
└───────────────────────────────┘

Monorepo detected at /Users/matt.volk/code/work/catalyst-deploy

Populating R2 incremental cache...
Successfully populated cache with 25 assets
Tag cache does not need populating

 ⛅️ wrangler 4.76.0
───────────────────
Your Worker has access to the following bindings:
Binding                                                                           Resource            Mode
env.NEXT_CACHE_DO_QUEUE (DOQueueHandler)                                          Durable Object      local
env.NEXT_TAG_CACHE_DO_SHARDED (DOShardedTagCache)                                 Durable Object      local
env.NEXT_CACHE_DO_PURGE (BucketCachePurge)                                        Durable Object      local
env.NEXT_INC_CACHE_R2_BUCKET (project-accd0361-2470-11f1-875e-1e6bd38089e2)       R2 Bucket           local
env.WORKER_SELF_REFERENCE (project-accd0361-2470-11f1-875e-1e6bd38089e2)          Worker              local [connected]
env.ASSETS                                                                        Assets              local

Still doesn't work

Finally, rename to .dev.vars:

$ cp .env.local .bigcommerce/.dev.vars
$ node ../packages/catalyst/dist/cli.js start
◢ @bigcommerce/catalyst v1.0.0-alpha.0                                                                                          4:15:19 PM


┌───────────────────────────────┐
│ OpenNext — Cloudflare preview │
└───────────────────────────────┘

Monorepo detected at /Users/matt.volk/code/work/catalyst-deploy

Populating R2 incremental cache...
Successfully populated cache with 25 assets
Tag cache does not need populating

 ⛅️ wrangler 4.76.0
───────────────────
Using secrets defined in .bigcommerce/.dev.vars
Your Worker has access to the following bindings:
Binding                                                                              Resource                  Mode
env.NEXT_CACHE_DO_QUEUE (DOQueueHandler)                                             Durable Object            local
env.NEXT_TAG_CACHE_DO_SHARDED (DOShardedTagCache)                                    Durable Object            local
env.NEXT_CACHE_DO_PURGE (BucketCachePurge)                                           Durable Object            local
env.NEXT_INC_CACHE_R2_BUCKET (project-accd0361-2470-11f1-875e-1e6bd38089e2)          R2 Bucket                 local
env.WORKER_SELF_REFERENCE (project-accd0361-2470-11f1-875e-1e6bd38089e2)             Worker                    local [connected]
env.ASSETS                                                                           Assets                    local
env.BIGCOMMERCE_STORE_HASH ("(hidden)")                                              Environment Variable      local
env.BIGCOMMERCE_CHANNEL_ID ("(hidden)")                                              Environment Variable      local
env.BIGCOMMERCE_STOREFRONT_TOKEN ("(hidden)")                                        Environment Variable      local
env.MAKESWIFT_SITE_API_KEY ("(hidden)")                                              Environment Variable      local
env.AUTH_SECRET ("(hidden)")                                                         Environment Variable      local
env.CLIENT_LOGGER ("(hidden)")                                                       Environment Variable      local
env.KV_LOGGER ("(hidden)")                                                           Environment Variable      local
env.DEFAULT_REVALIDATE_TARGET ("(hidden)")                                           Environment Variable      local
env.AUTH_TRUST_HOST ("(hidden)")                                                     Environment Variable      local
env.TRAILING_SLASH ("(hidden)")                                                      Environment Variable      local
env.ENABLE_ADMIN_ROUTE ("(hidden)")                                                  Environment Variable      local
env.B2B_API_TOKEN ("(hidden)")                                                       Environment Variable      local
env.B2B_API_HOST ("(hidden)")                                                        Environment Variable      local
env.CONTENTFUL_SPACE_ID ("(hidden)")                                                 Environment Variable      local
env.CONTENTFUL_ACCESS_TOKEN ("(hidden)")                                             Environment Variable      local
env.DATABASE_URL ("(hidden)")                                                        Environment Variable      local
env.DATABASE_AUTH_TOKEN ("(hidden)")                                                 Environment Variable      local
env.AUTH_RESEND_KEY ("(hidden)")                                                     Environment Variable      local

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline, agreed to symlink core/.env.local to core/.bigcommerce/.dev.vars if core/.bigcommerce/.dev.vars does not already exist.

Seperately, asked Cloudflare if there are there plans to support .env.local across all entry points (preview, dev, deploy, etc.). Currently .env.local only works during next dev via initOpenNextCloudflareForDev(), but opennextjs-cloudflare preview goes through wrangler which only reads .dev.vars. The inconsistency is a bit of a footgun — easy to assume .env.local works everywhere when it only works in dev.

@github-actions
Copy link
Contributor

Bundle Size Report

Comparing against baseline from c965f4d (2026-03-20).

No bundle size changes detected.

@matthewvolk matthewvolk force-pushed the CATALYST-1826-start-cmd-dev-vars branch from e69a84e to 375f476 Compare March 20, 2026 21:42
@matthewvolk matthewvolk changed the title fix(cli): copy .env.local to .dev.vars before preview fix(cli): symlink .env.local to .dev.vars before preview Mar 20, 2026
Wrangler reads secrets from .dev.vars, not .env.local. Create a symlink
from .bigcommerce/.dev.vars to .env.local before running
opennextjs-cloudflare preview so the local server has access to
environment variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants