Repository navigation
fix(deploy): keep local .env values out of native framework Worker bundles - #732
Merged
Merged
Conversation
…ndles `void deploy --platform cloudflare` bundles a framework's Worker output with Vite once more before uploading it. That build used the project root as its env directory, so Vite read the local `.env` and put every `VITE_*` value from it into `import.meta.env`, including keys that `env.ts` does not declare. A SvelteKit D1 app keeps an installed `void/env` as an import in its server output, so this build is where that module's `import.meta.env` is replaced. The uploaded Worker then returned the local `.env` value for `env.VITE_*` keys that the build shell does not set, while the browser bundle used the schema default. Managed deploys bundle from `.void/bundle` and were not affected. The bundle now sets `envDir: false`, as documented: builds ignore client values from `.env`. Shell values still apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cpojer
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a SvelteKit app on D1 with
voidinstalled from npm,void deploy --platform cloudflareputs theVITE_*values from the local.envinto the uploaded Worker:# .env VITE_API_ORIGIN=http://localhost:8787 VITE_LOCAL_NOTE=only-on-my-laptopWith
VITE_API_ORIGIN: url().default('https://api.example.com')inenv.tsand no value in the build shell, the deployed Worker answersenv.VITE_API_ORIGINwithhttp://localhost:8787, while the browser bundle hashttps://api.example.com.VITE_LOCAL_NOTEis not declared inenv.tsand is readable too. The docs say builds ignore client values from.env.Void's env plugin removes
.envclient values during Kit's build, but Kit's server build leaves an installedvoid/envas an import, so that module is not compiled there. Before the upload,prepareBundledBuildOutputbundles the adapter's Worker once more with Vite, with the project root asrootand noenvDir. Vite reads.envthere and replacesimport.meta.envinvoid/envwith its values. Managed deploys bundle the same entry from.void/bundle, which has no.env.Fix
The bundle sets
envDir: false. Vite reads no env files there; values from the build shell still reachimport.meta.env.Tests
packages/void/test/unit/cf-build-output.test.tsbundles a framework Worker that imports a package readingimport.meta.envas a whole, withVITE_ORIGINin.envandVITE_SHELL_ORIGINin the environment. The bundle contains the shell value and not the.envvalue. Without this fix, it contains both.The SvelteKit playground does not show the problem: it links
voidfrom the workspace, so Kit bundles it in its own build and the second bundle finds noimport.meta.envto replace.Verification
vp test run: 781 files pass, 1 skipped (16,159 tests pass, 29 skipped).vp run check: 33/33 pass.voidcopied intonode_modulesas a real directory: build, thenprepareCfFrameworkBuildOutputandbundleEntry, each run in Miniflare. Without this fix, the native Worker returns the.envvalues from an API route and rendershttp://localhost:8787in a page. With it, the native and managed Workers return the same values: none without a build-shell value, and the build-shell value whenVITE_API_ORIGINis set.void deployagainst Cloudflare, and Nuxt, Analog and Astro, which go through the same bundle.Related: #729 keeps local values out of Astro's Worker through a different path (Astro's env plugin). The two changes touch different files and don't depend on each other.
🤖 Generated with Claude Code