{"id":15711743,"url":"https://github.com/jacksteamdev/svelte-env-var-repro","last_synced_at":"2025-07-27T08:06:24.197Z","repository":{"id":247295979,"uuid":"825474158","full_name":"jacksteamdev/svelte-env-var-repro","owner":"jacksteamdev","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-08T00:42:39.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-19T00:24:28.395Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://svelte-env-var-repro.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacksteamdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-07T21:56:30.000Z","updated_at":"2025-05-11T00:11:30.000Z","dependencies_parsed_at":"2024-07-07T23:22:03.267Z","dependency_job_id":"3ca96ee7-4fc3-4c49-9a7a-174ecf5c1b8a","html_url":"https://github.com/jacksteamdev/svelte-env-var-repro","commit_stats":null,"previous_names":["jacksteamdev/svelte-env-var-repro"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jacksteamdev/svelte-env-var-repro","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksteamdev%2Fsvelte-env-var-repro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksteamdev%2Fsvelte-env-var-repro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksteamdev%2Fsvelte-env-var-repro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksteamdev%2Fsvelte-env-var-repro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacksteamdev","download_url":"https://codeload.github.com/jacksteamdev/svelte-env-var-repro/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksteamdev%2Fsvelte-env-var-repro/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267327534,"owners_count":24069442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T21:13:50.708Z","updated_at":"2025-07-27T08:06:24.168Z","avatar_url":"https://github.com/jacksteamdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SvelteKit Turbo Environment Variables Repro\n\nThe default Turbo environment variables patterns do not work in SvelteKit v2.0. Turbo has `VITE_*` for SvelteKit, but SvelteKit uses `PUBLIC_*` as the default prefix for public env vars.\n\n\u003e [!TIP]\n\u003e Turbo framework inference should use `PUBLIC_*` as the default prefix for env vars.\n\u003e Framework inference documentation should stress that variables not included in the framework defaults or explicitly in `turbo.json` will not be available for the build.\n\nThere is no prefix for private env vars. SvelteKit default is that anything not prefixed with `PUBLIC_` is private and can be used in routes. However, this means private env vars must be listed explicitly in `turbo.json` in the `env` array.\n\n## Instructions\n\n\u003e [!NOTE]\n\u003e See [this PR](https://github.com/jacksteamdev/svelte-env-var-repro/pull/1) for an issue demo.\n\nFollow these steps to demonstrate the issue.\n\n1. Run `npx create-turbo@latest -e with-svelte`\n2. Install `@sveltejs/adapter-vercel` and update `svelte.config.js`:\n\n```javascript\nimport adapter from '@sveltejs/adapter-vercel';\nimport { vitePreprocess } from '@sveltejs/vite-plugin-svelte';\n\n/** @type {import('@sveltejs/kit').Config} */\nconst config = {\n\t// Consult https://kit.svelte.dev/docs/integrations#preprocessors\n\t// for more information about preprocessors\n\tpreprocess: vitePreprocess(),\n\tkit: {\n\t\t// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.\n\t\t// If your environment is not supported or you settled on a specific environment, switch out the adapter.\n\t\t// See https://kit.svelte.dev/docs/adapters for more information about adapters.\n\t\tadapter: adapter()\n\t}\n};\n\nexport default config;\n```\n\n3. Add environment variables to `apps/web/.env` (this file is not in source control):\n\n```env\nPUBLIC_ENV_VAR=\"abc123\"\nSECRET_ENV_VAR=\"def456\"\n```\n\n3. Import `PUBLIC_ENV_VAR` to `apps/web/src/routes/+page.svelte`:\n\n```svelte\n\u003cscript lang=\"ts\"\u003e\n\timport { PUBLIC_ENV_VAR } from '$env/static/public';\n\timport { MyCounterButton } from '@repo/ui';\n\n\texport let data;\n\u003c/script\u003e\n\n\u003ch1\u003eTurbo Env Var Repro\u003c/h1\u003e\n\u003cMyCounterButton /\u003e\n\u003cp\u003eEnvironment variables:\u003c/p\u003e\n\u003cpre\u003e\n{JSON.stringify(\n\t\t{\n\t\t\t...data,\n\t\t\tPUBLIC_ENV_VAR: `Imported on the client from $env/static/public: ${PUBLIC_ENV_VAR}`\n\t\t},\n\t\tnull,\n\t\t2\n\t)}\n\u003c/pre\u003e\n```\n\n4. Import `SECRET_ENV_VAR` to `apps/web/src/routes/api/index.ts`:\n\n```svelte\nimport { SECRET_ENV_VAR } from '$env/static/private';\n\nexport function load() {\n\treturn {\n\t\tSECRET_ENV_VAR: `Loaded on the server from $env/static/private: ${SECRET_ENV_VAR}`\n\t};\n}\n```\n\n5. Run `pnpm dev` in `apps/web`. Open in the browser. The env vars are displayed as expected.\n\n6. Deploy to Vercel. The build will fail with an error similar to:\n\n```sh\nweb:build: error during build:\nweb:build: RollupError: \"PUBLIC_ENV_VAR\" is not exported by \"virtual:$env/static/public\", imported by \"src/routes/+page.svelte\".\nweb:build: file: /vercel/path0/apps/web/src/routes/+page.svelte:2:10\nweb:build: 1: \u003cscript lang=\"ts\"\u003e\nweb:build: 2:   import { PUBLIC_ENV_VAR } from '$env/static/public';\nweb:build:               ^\nweb:build: 3:   import { env } from '$env/dynamic/public';\nweb:build: 4:   import { MyCounterButton } from '@repo/ui';\n```\n\n1. Add `PUBLIC_ENV_VAR` and `SECRET_ENV_VAR` to the Vercel project settings UI. Redeploy the project. The build will fail with the same error.\n\n2. Update `turbo.json` to include `PUBLIC_*` and `PRIVATE_*` in the `env` array:\n\n```json\n{\n\t\"$schema\": \"https://turbo.build/schema.json\",\n\t\"tasks\": {\n\t\t\"build\": {\n\t\t\t\"dependsOn\": [\"^build\"],\n\t\t\t\"inputs\": [\"$TURBO_DEFAULT\", \".env*\"],\n\t\t\t\"outputs\": [\".svelte-kit/**\", \".vercel/**\"],\n\t\t\t\"env\": [\"PUBLIC_*\", \"SECRET_ENV_VAR\"]\n\t\t},\n\t\t\"lint\": {},\n\t\t\"dev\": {\n\t\t\t\"cache\": false,\n\t\t\t\"persistent\": true\n\t\t}\n\t}\n}\n```\n\n8. Redeploy to Vercel. The build will succeed.\n\n## Resources\n\n1. Discord thread: https://discord.com/channels/457912077277855764/1258475334744014859\n2. SvelteKit documentation for default env var prefixes:\n   1. Config: https://kit.svelte.dev/docs/configuration#env\n   2. Public: https://learn.svelte.dev/tutorial/env-static-public\n   3. Private: https://learn.svelte.dev/tutorial/env-static-private\n3. Turbo docs for environment variables:\n   1. Tasks must account for all env vars: https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#strict-mode\n   2. Add env vars to turbo.json: https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#adding-environment-variables-to-task-hashes\n   3. Don't set env vars at runtime: https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#avoid-creating-or-mutating-environment-variables-at-runtime\n   4. Config docs: https://turbo.build/repo/docs/reference/configuration#env\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacksteamdev%2Fsvelte-env-var-repro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacksteamdev%2Fsvelte-env-var-repro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacksteamdev%2Fsvelte-env-var-repro/lists"}