sveltejs/kit · error
`defineEnvVars` has moved — import it from `@sveltejs/kit/en
Error message
`defineEnvVars` has moved — import it from `@sveltejs/kit/env` instead
What it means
defineEnvVars was an internal SvelteKit API that has been removed from its old import location. Calling the stub exported from @sveltejs/kit always throws this migration message. It exists purely to point developers at the new import path rather than failing with an opaque 'undefined is not a function'.
Source
Thrown at packages/kit/src/exports/hooks/index.js:7
export { sequence } from './sequence.js';
/**
* @internal
*/
export function defineEnvVars() {
throw new Error(`\`defineEnvVars\` has moved — import it from \`@sveltejs/kit/env\` instead`);
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Remove the defineEnvVars call entirely — modern SvelteKit/Vite handles env loading automatically via import.meta.env and $env modules.
- If you truly need env helpers, import from '@sveltejs/kit/env' (per the error message) or use Vite's loadEnv in config files.
- Update any copied vite plugin/config code to the current @sveltejs/vite-plugin-svelte + SvelteKit API surface.
Example fix
// before
import { defineEnvVars } from '@sveltejs/kit';
defineEnvVars();
// after
// delete the call; use $env/static/public in app code or Vite loadEnv in config
import { loadEnv } from 'vite'; Defensive patterns
Strategy: try-catch
Validate before calling
import * as kit from '@sveltejs/kit';
if (typeof kit.defineEnvVars === 'function' && /moved/.test(String(kit.defineEnvVars))) {
console.warn('defineEnvVars is removed; drop the call or import from @sveltejs/kit/env');
} Type guard
function isRemovedApiError(e) {
return e instanceof Error && e.message.includes('defineEnvVars` has moved');
} Try / catch
try {
defineEnvVars();
} catch (e) {
if (e.message.includes('has moved')) {
console.warn('Migrating away from defineEnvVars — no action needed beyond removing this call.');
} else {
throw e;
}
} Prevention
- Read the SvelteKit changelog/migration guide when upgrading major versions.
- Search your codebase for defineEnvVars imports before upgrading.
- Avoid copying vite config snippets from outdated tutorials; use current @sveltejs/kit docs.
When it happens
Trigger: Importing { defineEnvVars } from '@sveltejs/kit' (or deep paths resolving to exports/hooks/index.js) and calling it — typically in a vite.config or svelte.config after upgrading SvelteKit.
Common situations: Upgrading from an older SvelteKit version where defineEnvVars was importable from '@sveltejs/kit'; following outdated tutorials or vendored Vite plugin code that still used it.
Related errors
- The `generateManifest` adapter API has been removed — use `g
- SvelteKit configuration (${keys}) no longer lives inside a `
- The `${keypath}` option has been removed. Please see the lis
- ${file} must export a variables object
- Cannot import `$app/*` modules other than `$app/env` inside
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/02923ad6eecaffbe.
Report an issue: GitHub.