Skip to content

Commit

Permalink
feat: validate config exports to improve error message (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 22, 2024
1 parent 8d07689 commit 342b134
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isAbsolute, join } from 'path';
import {
color,
logger,
isObject,
debounce,
getNodeEnv,
type RsbuildConfig,
Expand Down Expand Up @@ -125,6 +126,14 @@ export async function loadConfigByPath(configFile: string) {
return result;
}

if (!isObject(configExport)) {
throw new Error(
`Rsbuild config must be an object or a function that returns an object, get ${color.yellow(
configExport,
)}`,
);
}

return configExport;
} catch (err) {
logger.error(`Failed to load file: ${color.dim(configFile)}`);
Expand Down

0 comments on commit 342b134

Please sign in to comment.