Repository navigation
TanStack Start: add vite.loadEnv opt-out option to stop loading unprefixed .env keys into process.env #9037
jasonkuhrt
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Add an opt-out option (for example
vite: { loadEnv: false }) on TanStack Start's Vite plugin so callers whose build orchestrator already managesprocess.envcan stop@tanstack/start-plugin-corefrom loading unprefixed.envvalues intoprocess.env.Problem
In
@tanstack/start-plugin-core@1.170.0(packages/start-plugin-core/src/vite/plugin.ts:234),1.173.0, andmain(a47dc36d03,packages/start-plugin-core/src/vite/plugin.ts:270-277),tanStackStartViteunconditionally registerstanstack-start-core:load-env(packages/start-plugin-core/src/vite/load-env-plugin/plugin.ts:4-12), which runsObject.assign(process.env, loadEnv(config.mode, config.root, ""))during Vite'sconfigResolvedhook for bothserveandbuild.Even setting Vite's own
envDir: false(verified on Vite 8.4.0) only suppresses Vite's own.envloading (config.env/import.meta.envforVITE_*) — Start'stanstack-start-core:load-envplugin still reads unprefixed keys from.envfiles inconfig.rootand writes them intoprocess.env.For builds run under an external secret/env manager or a filesystem-tracing task cache, callers may want to prevent Start from writing
.envkeys intoprocess.envduringvite build(either alone while keeping Vite's publicVITE_*.envloading intact, or paired with Vite'senvDir: falseso neither Vite nor Start reads.envfiles). Todaypackages/start-plugin-core/src/vite/schema.ts:9-26exposes onlyvite.installDevServerMiddleware, with no supported option to disable Start'sloadEnvhook.Reproduction
Versions:
@tanstack/start-plugin-core@1.173.0(also verified on1.170.0andmaina47dc36d03),vite@8.4.0, Node 24.22.2 (macOS 27.2.1).{ unprefixedInProcessEnv: 'from-file', vitePublicEnv: null }— Start writes unprefixed.envkeys intoprocess.envduringbuildeven withenvDir: false. (WithouttanStackStartVite, the same Vite config withenvDir: falseyields{ unprefixedInProcessEnv: null, vitePublicEnv: null }.)Proposal
Add an optional
vite.loadEnv?: booleanoption (defaulting totrueto preserve existing behavior) on Start's plugin options, so callers can stop Start from mutatingprocess.envfrom.env(for examplevite: { loadEnv: command === "serve" }orvite: { loadEnv: false }, optionally combined with Vite's ownenvDir: falsewhen.envfiles should not be read at all).Happy to submit a PR if this option shape aligns with TanStack Start's plugin schema.
All reactions