File tree Expand file tree Collapse file tree
packages/docusaurus-mdx-loader/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -162,11 +162,21 @@ export async function mdxLoader(
162162 result = await processor . process ( { content, filePath} ) ;
163163 } catch ( errorUnknown ) {
164164 const error = errorUnknown as Error ;
165+
166+ // MDX can emit errors that have useful extra attributes
167+ const errorJSON = JSON . stringify ( error , null , 2 ) ;
168+ const errorDetails =
169+ errorJSON === '{}'
170+ ? // regular JS error case: print stacktrace
171+ error . stack ?? 'N/A'
172+ : // MDX error: print extra attributes + stacktrace
173+ `${ errorJSON } \n${ error . stack } ` ;
174+
165175 return callback (
166176 new Error (
167177 `MDX compilation failed for file ${ logger . path ( filePath ) } \nCause: ${
168178 error . message
169- } \nDetails:\n${ JSON . stringify ( error , null , 2 ) } `,
179+ } \nDetails:\n${ errorDetails } `,
170180 // TODO error cause doesn't seem to be used by Webpack stats.errors :s
171181 { cause : error } ,
172182 ) ,
You can’t perform that action at this time.
0 commit comments