fix(cli): symlink .env.local to .dev.vars before preview#2944
fix(cli): symlink .env.local to .dev.vars before preview#2944matthewvolk wants to merge 1 commit intoalphafrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
| consola.start('Copying .env.local to .bigcommerce/.dev.vars...'); | ||
| copyFileSync(envLocal, devVars); | ||
| consola.success('.dev.vars created'); |
There was a problem hiding this comment.
I thought wrangler/opennext can now read from .env.local?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yeah I think CF is trying to move to .env.local instead of .dev.vars.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
9449576 to
e69a84e
Compare
Bundle Size ReportComparing against baseline from No bundle size changes detected. |
e69a84e to
375f476
Compare
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.
375f476 to
42a860f
Compare
Summary
.env.localto.bigcommerce/.dev.varsbefore runningopennextjs-cloudflare previewin thestartcommand.dev.vars, not.env.local, and silently ignores symlinks.env.localis missing, to avoid breaking CI flowsTest plan
copyFileSyncmock added)pnpm test)catalyst build && catalyst startwith.env.localpresent — verify preview has env varscatalyst startwithout.env.local— verify warning is logged