vitejs/vite · error · Error

config must export or return an object.

Error message

config must export or return an object.

What it means

After loading and (if it is a function) calling the config export, Vite checks isObject(config). A config file must default-export or return a plain object; returning undefined, a string, an array, or a non-object triggers this error.

Solutions

  1. Ensure vite.config default-exports a plain object: export default defineConfig({ ... }).
  2. If the config is a function, make sure every code path returns an object.
  3. Avoid exporting arrays, strings, or class instances as the config.

Example fix

// before
export const config = { root: 'src' }  // no default export
// after
export default defineConfig({ root: 'src' })
Defensive patterns

Strategy: validation

Validate before calling

function isPlainObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }

Type guard

function isUserConfig(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Prevention

When it happens

Trigger: A vite.config whose default export is undefined (e.g. you forgot to write export default), or whose function form returns undefined. Also when the config has no default export at all and the named export is treated as the module.

Common situations: Typos like `export cons config = ...`; configs that conditionally return ({ }) only in some branches; using CommonJS module.exports = undefined; ESM configs missing a default export.

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/d9e701684f345306. Report an issue: GitHub.

Appendix: source

Thrown at packages/vite/src/node/config.ts:2428

  try {
    const { configExport, dependencies } = await (configLoader === 'bundle'
      ? bundleAndLoadConfigFile(
          resolvedPath,
          configRoot,
          logLevel,
          customLogger,
        )
      : configLoader === 'runner'
        ? runnerImportConfigFile(resolvedPath)
        : nativeImportConfigFile(resolvedPath))
    debug?.(`config file loaded in ${getTime()}`)

    const config = await (typeof configExport === 'function'
      ? configExport(configEnv)
      : configExport)
    if (!isObject(config)) {
      throw new Error(`config must export or return an object.`)
    }

    return {
      path: normalizePath(resolvedPath),
      config,
      dependencies,
    }
  } catch (e) {
    const logger = createLogger(logLevel, { customLogger })
    checkBadCharactersInPath('The config path', 'file', resolvedPath, logger)
    logger.error(colors.red(`failed to load config from ${resolvedPath}`), {
      error: e,
    })
    throw e
  }
}

async function nativeImportConfigFile(

View on GitHub (pinned to b4d66fee14)