{"record":{"id":"d9e701684f345306","repo":"vitejs/vite","slug":"config-must-export-or-return-an-object","errorCode":null,"errorMessage":"config must export or return an object.","messagePattern":"config must export or return an object\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/config.ts","lineNumber":2428,"sourceCode":"\n  try {\n    const { configExport, dependencies } = await (configLoader === 'bundle'\n      ? bundleAndLoadConfigFile(\n          resolvedPath,\n          configRoot,\n          logLevel,\n          customLogger,\n        )\n      : configLoader === 'runner'\n        ? runnerImportConfigFile(resolvedPath)\n        : nativeImportConfigFile(resolvedPath))\n    debug?.(`config file loaded in ${getTime()}`)\n\n    const config = await (typeof configExport === 'function'\n      ? configExport(configEnv)\n      : configExport)\n    if (!isObject(config)) {\n      throw new Error(`config must export or return an object.`)\n    }\n\n    return {\n      path: normalizePath(resolvedPath),\n      config,\n      dependencies,\n    }\n  } catch (e) {\n    const logger = createLogger(logLevel, { customLogger })\n    checkBadCharactersInPath('The config path', 'file', resolvedPath, logger)\n    logger.error(colors.red(`failed to load config from ${resolvedPath}`), {\n      error: e,\n    })\n    throw e\n  }\n}\n\nasync function nativeImportConfigFile(","sourceCodeStart":2410,"sourceCodeEnd":2446,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/config.ts#L2410-L2446","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos like `export cons config = ...`; configs that conditionally return ({ }) only in some branches; using CommonJS module.exports = undefined; ESM configs missing a default export.","solutions":["Ensure vite.config default-exports a plain object: export default defineConfig({ ... }).","If the config is a function, make sure every code path returns an object.","Avoid exporting arrays, strings, or class instances as the config."],"exampleFix":"// before\nexport const config = { root: 'src' }  // no default export\n// after\nexport default defineConfig({ root: 'src' })","handlingStrategy":"validation","validationCode":"function isPlainObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }","typeGuard":"function isUserConfig(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Always default-export a plain object from vite.config.","For function configs, ensure every branch returns an object."],"tags":["config","config-loader","esm","commonjs"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}