feat: move defineEnvVars to @sveltejs/kit/env - #16378
Merged
Merged
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/d90d2b8d095106dad63b574659d107862efa7008Open in |
🦋 Changeset detectedLatest commit: d90d2b8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…s`) is referenced by docs and JSDoc but is never wired into the package `exports` map or the type generation script, making `import { defineEnvVars } from '@sveltejs/kit/env'` throw `ERR_PACKAGE_PATH_NOT_EXPORTED`.
This commit fixes the issue reported at packages/kit/package.json:106
## Bug
The PR adds a new module `packages/kit/src/exports/env/index.js` exporting `defineEnvVars`, and updates docs (`documentation/docs/20-core-concepts/70-environment-variables.md`, 8 usages) and JSDoc/type links (`public.d.ts`, `types/index.d.ts`) to instruct users to `import { defineEnvVars } from '@sveltejs/kit/env'`.
However, the subpath was never registered:
1. **`packages/kit/package.json` `exports` map** had no `./env` entry. Node resolves subpath imports strictly against the `exports` field, so `import ... from '@sveltejs/kit/env'` throws `ERR_PACKAGE_PATH_NOT_EXPORTED` at runtime/build time. Concrete trigger: any consumer following the new docs example would fail immediately on import.
2. **`packages/kit/scripts/generate-dts.js` `modules` map** had no `'@sveltejs/kit/env'` entry, so `pnpm generate:types` did not emit a `declare module '@sveltejs/kit/env'` block. The docs link `@sveltejs-kit-env#defineEnvVars` and TS resolution both depend on that generated declaration.
## Fix
- Added a `./env` entry to the `exports` map mirroring the `./hooks` convention:
```json
"./env": {
"types": "./types/index.d.ts",
"import": "./src/exports/env/index.js"
}
```
- Added `'@sveltejs/kit/env': 'src/exports/env/index.js'` to the `modules` map in `generate-dts.js`.
- Regenerated `types/index.d.ts` (`node scripts/generate-dts.js`), which now contains the `declare module '@sveltejs/kit/env'` block exporting `defineEnvVars`.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
6 tasks
dummdidumm
approved these changes
Jul 17, 2026
dummdidumm
left a comment
Member
There was a problem hiding this comment.
looks good but not merging because I'm not 100% sure if you meant this to go into main (because of the "deprecate first, remove later" bit)
Member
Author
|
Whoops, yes I did - was branched off main locally but forgot to replace the default branch |
Merged
Rich-Harris
pushed a commit
that referenced
this pull request
Jul 17, 2026
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @sveltejs/kit@2.70.0 ### Minor Changes - feat: move `defineEnvVars` to `@sveltejs/kit/env` ([#16378](#16378)) ### Patch Changes - fix: enable CSRF protection in builds with a non-production `NODE_ENV` value ([#16313](#16313)) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
6 tasks
Rich-Harris
pushed a commit
that referenced
this pull request
Jul 18, 2026
As invited in [#16195](#16195 (comment)), `defineEnvVars` now accepts a function in place of a Standard Schema. The contract mirrors `defineParams`: the function returns the (possibly transformed) value, or `undefined` if the value is invalid. It can also throw, in which case the error's message appears in the startup report, since a bare `undefined` can't carry one. Throwing is the only rejection path, returning any value including `undefined` accepts it, so a function validator can describe an optional variable without a fallback. `defineEnvVars` normalizes functions to standard schemas, so `validate` and the generated `env.d.ts` types are unchanged (the return type is mapped like `DefinedParams`). Also adds the `@sveltejs/kit/env` tsconfig paths entry that #16378 didn't need yet. Built on top of #16401. --- ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. ### Tests - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check` ### Changesets - [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`. ### Edits - [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.
Open
6 tasks
renovate Bot
added a commit
to cigaleapp/cigale
that referenced
this pull request
Jul 27, 2026
##### [v2.70.1](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2701) ##### Patch Changes - docs: update links to hooks documentation ([#16417](sveltejs/kit#16417)) ##### [v2.70.0](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2700) ##### Minor Changes - feat: move `defineEnvVars` to `@sveltejs/kit/env` ([#16378](sveltejs/kit#16378)) ##### Patch Changes - fix: enable CSRF protection in builds with a non-production `NODE_ENV` value ([#16313](sveltejs/kit#16313)) ##### [v2.69.3](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2693) ##### Patch Changes - fix: detect destructured `load` and `actions` exports during type generation ([#16329](sveltejs/kit#16329)) - fix: ensure CSS URL references are absolute when `paths.relative` is `false` ([#16315](sveltejs/kit#16315)) - fix: align MAX\_COOKIE\_SIZE with RFC 6265bis ([#16322](sveltejs/kit#16322))
renovate Bot
added a commit
to cigaleapp/cigale
that referenced
this pull request
Jul 27, 2026
##### [v2.70.1](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2701) ##### Patch Changes - docs: update links to hooks documentation ([#16417](sveltejs/kit#16417)) ##### [v2.70.0](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2700) ##### Minor Changes - feat: move `defineEnvVars` to `@sveltejs/kit/env` ([#16378](sveltejs/kit#16378)) ##### Patch Changes - fix: enable CSRF protection in builds with a non-production `NODE_ENV` value ([#16313](sveltejs/kit#16313)) ##### [v2.69.3](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2693) ##### Patch Changes - fix: detect destructured `load` and `actions` exports during type generation ([#16329](sveltejs/kit#16329)) - fix: ensure CSS URL references are absolute when `paths.relative` is `false` ([#16315](sveltejs/kit#16315)) - fix: align MAX\_COOKIE\_SIZE with RFC 6265bis ([#16322](sveltejs/kit#16322))
gwennlbh
pushed a commit
to cigaleapp/cigale
that referenced
this pull request
Jul 27, 2026
##### [v2.70.1](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2701) ##### Patch Changes - docs: update links to hooks documentation ([#16417](sveltejs/kit#16417)) ##### [v2.70.0](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2700) ##### Minor Changes - feat: move `defineEnvVars` to `@sveltejs/kit/env` ([#16378](sveltejs/kit#16378)) ##### Patch Changes - fix: enable CSRF protection in builds with a non-production `NODE_ENV` value ([#16313](sveltejs/kit#16313)) ##### [v2.69.3](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2693) ##### Patch Changes - fix: detect destructured `load` and `actions` exports during type generation ([#16329](sveltejs/kit#16329)) - fix: ensure CSS URL references are absolute when `paths.relative` is `false` ([#16315](sveltejs/kit#16315)) - fix: align MAX\_COOKIE\_SIZE with RFC 6265bis ([#16322](sveltejs/kit#16322)) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Realised that it'll be easier to do this in stages, deprecating it first rather than erroring immediately (#16375). This way we can keep the docs intact, and allow svelte.dev to continue building.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits