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

  1. Remove the defineEnvVars call entirely — modern SvelteKit/Vite handles env loading automatically via import.meta.env and $env modules.
  2. If you truly need env helpers, import from '@sveltejs/kit/env' (per the error message) or use Vite's loadEnv in config files.
  3. 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

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


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/02923ad6eecaffbe. Report an issue: GitHub.