Skip to content

Using explicitEnvironmentVariables tries to import _app/env.js despite not emitting it. #15985

Description

@minht11

Describe the bug

I am using new explicitEnvironmentVariables option, with 2 static variables.

Generate index.html script includes import for _app/env.js, despite it not existing.

__sveltekit_1fs6yae = {
						base: "",
						env: null
					};

					const element = document.currentScript.parentElement;

					import("/_app/env.js").then(({ env }) => {
						__sveltekit_1fs6yae.env = env;

						Promise.all([
							import("/_app/immutable/entry/start.DBxPQlil.js"),
							import("/_app/immutable/entry/app.D9hp4Ypm.js")
						]).then(([kit, app]) => {
							kit.start(app, element, {
									node_ids: [0, 13],
									data: [null,null],
									form: null,
									error: null
								});
						});
					});
				}

service worker file includes importScripts(/_app/env.script.js) but that file also doesn't exist.

Variables themselves are inlined correctly it just that import is also added into html/service worker entry points.

interestingly vite preview works fine and does not contain import("/_app/env.js") but actual source output does.

Reproduction

  1. Goto https://stackblitz.com/edit/sveltejs-kit-template-default-597qc6h8?file=.svelte-kit%2Foutput%2Fprerendered%2Fpages%2Findex.html
  2. Run pnpm run build.
  3. Go to .svelte-kit/output/prerendered/pages/index.html.
  4. Observe entry script imports env.js despite it not existing.

Logs

System Info

System:
    OS: macOS 26.5.1
    CPU: (10) arm64 Apple M4
    Memory: 315.45 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 26.2.0 - /Users/justinas/.proto/tools/node/26.2.0/bin/node
    Yarn: 4.6.0 - /Users/justinas/.proto/shims/yarn
    npm: 11.13.0 - /Users/justinas/.proto/tools/node/26.2.0/bin/npm
    pnpm: 11.5.2 - /Users/justinas/.proto/tools/pnpm/11.5.2/shims/pnpm
  Browsers:
    Brave Browser: 148.1.90.128
    Chrome: 149.0.7827.53
    Chrome Canary: 151.0.7881.0
    Firefox: 151.0.1
    Safari: 26.5
    Safari Technology Preview: 26.0
  npmPackages:
    @sveltejs/adapter-static: 3.0.10 => 3.0.10 
    @sveltejs/kit: 2.63.1 => 2.63.1 
    svelte: 5.56.2 => 5.56.2 
    vite: 8.0.16 => 8.0.16

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions