Skip to content

chore: make set_env synchronous#16060

Merged
benmccann merged 2 commits into
mainfrom
sync-set-env
Jun 16, 2026
Merged

chore: make set_env synchronous#16060
benmccann merged 2 commits into
mainfrom
sync-set-env

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

Didn't get a chance to review #16058, but I think we should extract the env stuff out into a separate module, so that we don't need the dynamic import in set_env — not really an issue during build, but adds unnecessary microtasks on every server.init(...) at runtime

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a5203e1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment thread packages/kit/src/core/postbuild/analyse.js Outdated
…in analyse.js references `set_env`, which was removed from the `ServerInternalModule` interface, causing a TS2339 type-check error.

This commit fixes the issue reported at packages/kit/src/core/postbuild/analyse.js:64

## Bug

In this PR, `set_env` was removed from the `ServerInternalModule` interface in `internal.d.ts` (no `set_env` matches found there) and is now declared only on the `__sveltekit/env` ambient module:

```ts
// ambient-private.d.ts
export function set_env(environment: Record<string, string>): void;
```

However, `packages/kit/src/core/postbuild/analyse.js` still annotates the dynamic `env.js` import with the old type:

```js
/** @type {import('types').ServerInternalModule} */
const { set_env } = await import(pathToFileURL(`${server_root}/server/env.js`).href);
set_env(env);
```

Destructuring `set_env` from a value typed as `ServerInternalModule` — which no longer has that member — triggers **TS2339: Property 'set_env' does not exist on type 'ServerInternalModule'** under `pnpm check` (tsc with `checkJs`).

The analogous code in `prerender.js` was correctly updated to use `@type {import('__sveltekit/env')}`.

## Trigger

Running `pnpm check` will fail on `analyse.js` line 64-65 because `set_env` is no longer a member of `ServerInternalModule`.

## Fix

Changed the annotation in `analyse.js` to `@type {import('__sveltekit/env')}`, matching the corrected code in `prerender.js`.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
@svelte-docs-bot

Copy link
Copy Markdown

@benmccann benmccann merged commit 0ccdb68 into main Jun 16, 2026
27 checks passed
@benmccann benmccann deleted the sync-set-env branch June 16, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants