diff --git a/packages/gatsby-plugin-mdx/src/error-utils.ts b/packages/gatsby-plugin-mdx/src/error-utils.ts index ca385a96c0abf..e2cbda7cde5fb 100644 --- a/packages/gatsby-plugin-mdx/src/error-utils.ts +++ b/packages/gatsby-plugin-mdx/src/error-utils.ts @@ -9,20 +9,24 @@ export const ERROR_CODES = { export const ERROR_MAP = { [ERROR_CODES.MdxCompilation]: { text: (context: { absolutePath: string; errorMeta: any }): string => - `Failed to compile the file "${context.absolutePath}". Original error message: \n\n${context.errorMeta.message}`, + `Failed to compile the file "${context.absolutePath}". Original error message:\n\n${context.errorMeta.message}`, level: `ERROR`, type: `PLUGIN`, category: `USER`, }, [ERROR_CODES.NonExistentFileNode]: { - text: (context: { resourcePath: string }): string => - `Unable to locate the GraphQL File node for ${context.resourcePath}`, + text: (context: { resourcePath: string; mdxPath?: string }): string => + `Unable to locate the GraphQL File node for ${context.resourcePath}${ + context.mdxPath ? `\nFile: ${context.mdxPath}` : `` + }`, level: `ERROR`, type: `PLUGIN`, }, [ERROR_CODES.InvalidAcornAST]: { - text: (context: { resourcePath: string }): string => - `Invalid AST. Parsed source code did not return valid output. File:\n${context.resourcePath}`, + text: (context: { resourcePath: string; mdxPath?: string }): string => + `Invalid AST. Parsed source code did not return valid output.\n\nTemplate:\n${ + context.resourcePath + }${context.mdxPath ? `\nFile: ${context.mdxPath}` : ``}`, level: `ERROR`, type: `PLUGIN`, category: `USER`, diff --git a/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts b/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts index 2f58b39bbaaa6..c64a63d0d8dba 100644 --- a/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts +++ b/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts @@ -39,6 +39,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.NonExistentFileNode, context: { resourcePath: this.resourcePath, + mdxPath, }, }) } @@ -71,6 +72,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.InvalidAcornAST, context: { resourcePath: this.resourcePath, + mdxPath, }, }) } @@ -249,6 +251,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.InvalidAcornAST, context: { resourcePath: this.resourcePath, + mdxPath, }, error, })