Describe the bug
Summary
After upgrading from:
@sveltejs/kit@2.27.0 → @sveltejs/kit@2.37.0
- Edit: the errors appear on
2.36.3, up until 2.36.2 there are no errors
my production app (built with adapter-node and deployed to GCP, where runtime env vars are passed via YAML) throws a client-side runtime error:
TypeError: Cannot read properties of undefined (reading 'env')
This error only appears in the production deployment that uses runtime YAML-injected environment variables (Cloud Run/GCP) and when running the docker container using docker build -t env-bug -f Dockerfile.dev . & docker run -e PORT=8080 -p 8080:8080 env-bug.
It does not appear in pnpm dev or in pnpm preview locally.
Environment
- SvelteKit:
@sveltejs/kit@2.37.0
- Svelte:
5.38.6 and 5.38.7 (both reproduce)
- Vite:
7.0.6 and 7.1.4 (already on Vite 7 before upgrade)
- Node:
22.14.0
- Adapter:
@sveltejs/adapter-node
- Runtime: GCP Cloud Run (env vars injected at runtime from YAML)
- Local:
pnpm dev / pnpm preview → no error
What I observed
-
Browser console shows crash pointing to a client chunk. Example snippet from failing chunk:
const e = globalThis.__sveltekit_1f326rc.env;
export { e };
-
grep shows all process.env occurrences are in server output and adapter-node chunks:
.svelte-kit/output/server/chunks/TextUtils.js:635: const qrCodeUrl = process.env.PUBLIC_APP_URL || "https://example.com";
.svelte-kit/adapter-node/chunks/TextUtils.js:635: const qrCodeUrl = process.env.PUBLIC_APP_URL || "https://example.com";
-
grep -R "process.env" .svelte-kit/output/client -n → empty (no process.env usage in client bundle).
-
Tried Vite shim:
define: { 'process.env': {} }
→ did not fix (error persists).
-
Upgraded related deps (Firebase etc.) → no change.
-
Error appeared right after upgrading SvelteKit version.
What I tried (and did not work)
define: { 'process.env': {} } → no effect.
- Ensured no client references to
process.env (grep confirms).
- Verified server chunks use
process.env.PUBLIC_* (expected).
- Tried latest Svelte
5.38.7 → still fails.
- Upgraded Firebase & other deps → no effect.
Possible cause
- Maybe a regression in Kit’s runtime bootstrap or adapter-node env serialization between 2.27 → 2.37.
Request
- Please advise whether this is a bug in Kit’s client runtime or if I’m missing a configuration step for adapter-node + runtime YAML envs introduced after Kit
2.27.0.
Reproduction
(say that 5 times fast)
Steps to reproduce
-
pnpm i
-
Build with pnpm build
-
GCP deploy OR docker run
--- GCP ---
3.1. Create the project in Cloud Run and enable necessary API's (Artifact Registry API, Cloud Run API)
3.2. Deploy to GCP Cloud Run without baking .env into the image (envs are provided only at runtime via YAML) using pnpm deploy:gcp which needs gcloud cli installed.
--- DOCKER RUN ---
3.1. Build the image with docker build -t env-bug -f Dockerfile.dev .
3.2. Run the container with docker run -e PORT=8080 -p 8080:8080 env-bug
-
Open the app in the browser.
-
Observe the console error:
TypeError: Cannot read properties of undefined (reading 'env')
Logs
No errors in server console.
Client console errors: TypeError: Cannot read properties of undefined (reading 'env') at BKRsM9ub.js:1:40 handleError @ app.DFEW0Jxm.js:2 F @ BXmFm1FW.js:11 Fn @ BXmFm1FW.js:11 await in Fn Wn @ BXmFm1FW.js:10 await in Wn (anonymous) @ bg:43 Promise.then (anonymous) @ bg:42 BKRsM9ub.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'env') at BKRsM9ub.js:1:40 (anonymous) @ BKRsM9ub.js:1 BKRsM9ub.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'env') at BKRsM9ub.js:1:40
System Info
System:
OS: Linux 6.16 Fedora Linux 42 (KDE Plasma Desktop Edition)
CPU: (16) x64 AMD Ryzen 9 7940HS w/ Radeon 780M Graphics
Memory: 38.46 GB / 54.72 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.15.1 - ~/.local/share/pnpm/pnpm
Browsers:
Brave Browser: 139.1.81.137
npmPackages:
@sveltejs/adapter-node: ^5.3.1 => 5.3.1
@sveltejs/kit: ^2.27.0 => 2.27.0
@sveltejs/vite-plugin-svelte: ^6.1.4 => 6.1.4
svelte: ^5.38.7 => 5.38.7
vite: ^7.1.4 => 7.1.4
Severity
blocking an upgrade
Additional Information
No response
Describe the bug
Summary
After upgrading from:
@sveltejs/kit@2.27.0→@sveltejs/kit@2.37.02.36.3, up until2.36.2there are no errorsmy production app (built with
adapter-nodeand deployed to GCP, where runtime env vars are passed via YAML) throws a client-side runtime error:This error only appears in the production deployment that uses runtime YAML-injected environment variables (Cloud Run/GCP) and when running the docker container using
docker build -t env-bug -f Dockerfile.dev .&docker run -e PORT=8080 -p 8080:8080 env-bug.It does not appear in
pnpm devor inpnpm previewlocally.Environment
@sveltejs/kit@2.37.05.38.6and5.38.7(both reproduce)7.0.6and7.1.4(already on Vite 7 before upgrade)22.14.0@sveltejs/adapter-nodepnpm dev/pnpm preview→ no errorWhat I observed
Browser console shows crash pointing to a client chunk. Example snippet from failing chunk:
grepshows allprocess.envoccurrences are in server output and adapter-node chunks:grep -R "process.env" .svelte-kit/output/client -n→ empty (noprocess.envusage in client bundle).Tried Vite shim:
→ did not fix (error persists).
Upgraded related deps (Firebase etc.) → no change.
Error appeared right after upgrading SvelteKit version.
What I tried (and did not work)
define: { 'process.env': {} }→ no effect.process.env(grep confirms).process.env.PUBLIC_*(expected).5.38.7→ still fails.Possible cause
Request
2.27.0.Reproduction
Repro Repo
Steps to reproduce
pnpm iBuild with
pnpm buildGCP deploy OR docker run
--- GCP ---
3.1. Create the project in Cloud Run and enable necessary API's (Artifact Registry API, Cloud Run API)
3.2. Deploy to GCP Cloud Run without baking
.envinto the image (envs are provided only at runtime via YAML) usingpnpm deploy:gcpwhich needs gcloud cli installed.--- DOCKER RUN ---
3.1. Build the image with
docker build -t env-bug -f Dockerfile.dev .3.2. Run the container with
docker run -e PORT=8080 -p 8080:8080 env-bugOpen the app in the browser.
Observe the console error:
Logs
System Info
System: OS: Linux 6.16 Fedora Linux 42 (KDE Plasma Desktop Edition) CPU: (16) x64 AMD Ryzen 9 7940HS w/ Radeon 780M Graphics Memory: 38.46 GB / 54.72 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Binaries: Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm pnpm: 10.15.1 - ~/.local/share/pnpm/pnpm Browsers: Brave Browser: 139.1.81.137 npmPackages: @sveltejs/adapter-node: ^5.3.1 => 5.3.1 @sveltejs/kit: ^2.27.0 => 2.27.0 @sveltejs/vite-plugin-svelte: ^6.1.4 => 6.1.4 svelte: ^5.38.7 => 5.38.7 vite: ^7.1.4 => 7.1.4Severity
blocking an upgrade
Additional Information
No response