Skip to content

Cloudflare integration + vinext 1.2: built worker crashes at boot (initVarlockEnv failed) #1234

Closed

Description

@AndreasGalster2

varlock version

@varlock/cloudflare-integration 1.6.2

Steps to reproduce

Setup

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.

vinext 1.2.0 · vite 8.0.14 · react 19.2.6 · varlock 1.23.0 ·
@varlock/cloudflare-integration 1.6.2 · wrangler 4.151.0 · macOS arm64

Repro

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

  1. Is varlock/env expected to boot in a vinext-bundled worker under stock
    wrangler dev? If yes, what supplies __VARLOCK_ENV there?
  2. 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).

System Info

Any additional comments?

No response

Activity

  1. pullfrog commented on Oct 16, 2026

    @pullfrog
    Contributor
  2. theoephraim commented on Oct 16, 2026

    @theoephraim
    Member

    Thanks for the clean repro, that made this quick.

    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:

    1. 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.
    2. 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.

  3. github-actions commented on Oct 19, 2026

    @github-actions
    Contributor

    ✅ 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.

  4. added a commit that references this issue on Oct 19, 2026
    0997aa3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions