oven-sh/bun · error · TypeError

bun-svelte-plugin: compilerOptions must be an object

Error message

bun-svelte-plugin: compilerOptions must be an object

What it means

validateOptions() requires compilerOptions, when provided, to be an object — the Svelte compiler options bag (customElement, runes, modernAst, namespace, ...). Passing a string, array, number, or other non-object type throws this TypeError at plugin configuration time.

Source

Thrown at packages/bun-plugin-svelte/src/options.ts:53

  assert(options && typeof options === "object", new TypeError("bun-svelte-plugin: options must be an object"));
  const opts = options as Record<keyof SvelteOptions, unknown>;

  if (opts.forceSide != null) {
    if (typeof opts.forceSide !== "string") {
      throw new TypeError("bun-svelte-plugin: forceSide must be a string, got " + typeof opts.forceSide);
    }
    switch (opts.forceSide) {
      case "client":
      case "server":
        break;
      default:
        throw new TypeError(`bun-svelte-plugin: forceSide must be either 'client' or 'server', got ${opts.forceSide}`);
    }
  }

  if (opts.compilerOptions) {
    if (typeof opts.compilerOptions !== "object") {
      throw new TypeError("bun-svelte-plugin: compilerOptions must be an object");
    }
  }
}

/**
 * @internal
 */
export function getBaseCompileOptions(pluginOptions: SvelteOptions, config: Partial<BuildConfig>): CompileOptions {
  let {
    development = false,
    compilerOptions: { customElement, runes, modernAst, namespace } = kEmptyObject as OverrideCompileOptions,
  } = pluginOptions;
  const { minify = false } = config;

  const shouldMinify = Boolean(minify);
  const {
    whitespace: minifyWhitespace,
    syntax: _minifySyntax,

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Pass compilerOptions as an object: Bun.svelte({ compilerOptions: { runes: true } })
  2. Leave it out to use the defaults derived by getBaseCompileOptions()
  3. Keep values that are compiler flags (runes, customElement, ...) nested inside compilerOptions, not at the top level

Example fix

// before
Bun.svelte({ compilerOptions: 'svelte' });

// after
Bun.svelte({ compilerOptions: { runes: true } });
Defensive patterns

Strategy: type-guard

Validate before calling

if (opts.compilerOptions != null && typeof opts.compilerOptions !== 'object') {
  throw new TypeError('compilerOptions must be an object');
}

Type guard

const isCompilerOptions = (v: unknown): v is BunSveltePlugin.OverrideCompileOptions =>
  !!v && typeof v === 'object' && !Array.isArray(v);

Prevention

When it happens

Trigger: Bun.svelte({ compilerOptions: 'svelte' }), compilerOptions: ['runes'], or options spread from a flat config where compilerOptions was never nested (e.g. putting runes: true at the top level and misassigning the result).

Common situations: Confusing the plugin's own options with the Svelte compiler options; passing a JSON-parsed value that is a string; migrating configs from vite-plugin-svelte with different nesting.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/6cebfd8a3a322545. Report an issue: GitHub.