diff --git a/compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts b/compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts index 5ea6f9862815..3a3010dd2f62 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts @@ -188,6 +188,7 @@ export class CompilerError extends Error { constructor(...args: Array) { super(...args); this.name = 'ReactCompilerError'; + this.details = []; } override get message(): string { @@ -197,7 +198,10 @@ export class CompilerError extends Error { override set message(_message: string) {} override toString(): string { - return this.details.map(detail => detail.toString()).join('\n\n'); + if (Array.isArray(this.details)) { + return this.details.map(detail => detail.toString()).join('\n\n'); + } + return this.name; } push(options: CompilerErrorDetailOptions): CompilerErrorDetail {