You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cloudflare integration + vinext 1.2: built worker crashes at boot (initVarlockEnv failed) #1234
Tiny vinext 1.2 App Router app (one page reading ENV.* from varlock/env), varlockCloudflareVitePlugin() in place of cloudflare(), local .env file
with dummy values. No Infisical, no credentials, no deploy involved.
pnpm install
./node_modules/.bin/vite build # green
./node_modules/.bin/wrangler dev --config dist/server/wrangler.json
Actual
Worker crashes before serving anything:
Uncaught Error: initVarlockEnv failed
at null.<anonymous> (_next/static/env-Dh14o1ps.js:3:5)
plus the "no resolved env found" remediation text. Same under varlock run -- wrangler dev. Verified from a clean checkout
(rm -rf node_modules dist, fresh install, rebuild).
What works (control cases in the README)
vite dev → 200, 🔒 [varlock] injecting resolved env logged, .env
value rendered. Dev-mode injection is fine.
Same app with plain cloudflare() and no varlock/env import → builds,
boots, serves 200. Harness is fine; the integration is the variable.
Questions
Is varlock/env expected to boot in a vinext-bundled worker under stock wrangler dev? If yes, what supplies __VARLOCK_ENV there?
Our deploy path is vinext-cloudflare deploy, not wrangler deploy. Docs
say only varlock-wrangler produces the blob — any supported way to get it
with a non-wrangler deploy tool, or is varlock-wrangler a hard requirement?
What is expected?
No worker crash
What is actually happening?
Actual
Worker crashes before serving anything:
Uncaught Error: initVarlockEnv failed
at null.<anonymous> (_next/static/env-Dh14o1ps.js:3:5)
plus the "no resolved env found" remediation text. Same under varlock run -- wrangler dev. Verified from a clean checkout
(rm -rf node_modules dist, fresh install, rebuild).
What's happening: the built Worker only gets its env from a __VARLOCK_ENV binding. vite dev and vite preview inject it for you, and varlock-wrangler dev / varlock-wrangler deploy supply it when running wrangler against the build output. Plain wrangler dev does neither, so initVarlockEnv has nothing to load. varlock run -- wrangler dev can't help either: workerd never sees the host process env.
On your repro this works as-is:
./node_modules/.bin/vite build
./node_modules/.bin/varlock-wrangler dev --config dist/server/wrangler.json --port 8788
So to answer your questions:
No, stock wrangler dev isn't expected to boot it. Use varlock-wrangler dev --config dist/server/wrangler.json (or vite preview) as the start script.
vinext-cloudflare deploy calls wrangler's versions upload / deploy through wrangler's API rather than spawning the wrangler binary, so there's no seam for varlock-wrangler to sit in front of it. Use vite build && varlock-wrangler deploy --config dist/server/wrangler.json instead. It deploys the same build output; what you lose is vinext's cache-warming flags. Supporting the new cf CLI / cloudflare.config.ts flow is on our list.
Changes coming out of this:
the Worker now fails at boot with a specific message pointing at varlock-wrangler dev / deploy instead of the generic initVarlockEnv advice
a vinext guide in the docs (setup, script swap, deploy, troubleshooting)
a vinext example in varlock-examples
Separately, while building the example we found that console.log(ENV.SECRET) inside a Server Component leaked the raw value into the dev-mode RSC payload through React's console replay (varlock's leak detection then truncated the page). That's fixed in the same release.
✅ A fix has been merged to main in #1236 and will ship in the next release. GitHub auto-closed this issue on merge, but the change isn't published yet.
Activity
pullfrog commentedon Oct 16, 2026
theoephraim commentedon Oct 16, 2026
Thanks for the clean repro, that made this quick.
What's happening: the built Worker only gets its env from a
__VARLOCK_ENVbinding.vite devandvite previewinject it for you, andvarlock-wrangler dev/varlock-wrangler deploysupply it when running wrangler against the build output. Plainwrangler devdoes neither, soinitVarlockEnvhas nothing to load.varlock run -- wrangler devcan't help either: workerd never sees the host process env.On your repro this works as-is:
So to answer your questions:
wrangler devisn't expected to boot it. Usevarlock-wrangler dev --config dist/server/wrangler.json(orvite preview) as thestartscript.vinext-cloudflare deploycalls wrangler'sversions upload/deploythrough wrangler's API rather than spawning thewranglerbinary, so there's no seam forvarlock-wranglerto sit in front of it. Usevite build && varlock-wrangler deploy --config dist/server/wrangler.jsoninstead. It deploys the same build output; what you lose is vinext's cache-warming flags. Supporting the newcfCLI /cloudflare.config.tsflow is on our list.Changes coming out of this:
varlock-wrangler dev/deployinstead of the genericinitVarlockEnvadviceSeparately, while building the example we found that
console.log(ENV.SECRET)inside a Server Component leaked the raw value into the dev-mode RSC payload through React's console replay (varlock's leak detection then truncated the page). That's fixed in the same release.github-actions commentedon Oct 19, 2026
✅ A fix has been merged to
mainin #1236 and will ship in the next release. GitHub auto-closed this issue on merge, but the change isn't published yet.Cloudflare: clear error for a missing __VARLOCK_ENV binding, redact R…