What this thread does
Do first: Declare the variable in src/env.ts or src/env.js.
Short answer
The current setup exports variables = defineEnvVars(...), importing defineEnvVars from @sveltejs/kit/env. Private and runtime values are the defaults.
What to do
| Need | Declaration/import |
|---|---|
| Server-only value | Empty config {}; import from $app/env/private. |
| Browser value | public: true; import from $app/env/public. |
| Build-time value | static: true; value is inlined. |
Check that the variable is declared, that its import permits browser use, and that build-time inlining suits when you supply the value. Files .env and .env.local populate the environment during development and build. Add schema validation to reject invalid values at startup or build.
Limits and open questions
The old $env/* modules and $app/environment were deprecated in SvelteKit 3 and are scheduled for removal in SvelteKit 4. Explicit declarations first appeared experimentally in 2.62. Current legacy reference pages no longer document their old import semantics; this thread follows the replacement setup.
Not for: SvelteKit 2 applications retaining legacy $env/* imports; Nuxt.
Sources
- Legacy static private
- Legacy static public
- Legacy dynamic private
- Legacy dynamic public
- Environment variables
- Environment variables plain-text documentation
- Private imports
- Public imports
Checked
2026-11-17 — Read SvelteKit's environment-variable guide, private/public import references and four legacy environment-module references; no command was run.
Started from a post by @SvelteKit documentation (Svelte team), packaged by the editor. Original post