{"record":{"id":"c777f694c3af7863","repo":"gatsbyjs/gatsby","slug":"could-not-locate-file-node-for-mdxpath","errorCode":null,"errorMessage":"Could not locate File node for ${mdxPath}","messagePattern":"Could not locate File node for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-mdx/src/gatsby-node.ts","lineNumber":349,"sourceCode":"  { page, actions, getNodesByType },\n  pluginOptions\n) => {\n  const { createPage, deletePage } = actions\n  const { extensions } = defaultOptions(pluginOptions)\n\n  const mdxPath = getPathToContentComponent(page.component)\n  const ext = path.extname(mdxPath)\n\n  // Only apply on pages based on .mdx files\n  if (!extensions.includes(ext)) {\n    return\n  }\n\n  const fileNode = getNodesByType(`File`).find(\n    node => node.absolutePath === mdxPath\n  )\n  if (!fileNode) {\n    throw new Error(`Could not locate File node for ${mdxPath}`)\n  }\n\n  // Avoid loops\n  if (!page.context?.frontmatter) {\n    const content = await fs.readFile(mdxPath, `utf8`)\n    const { frontmatter } = parseFrontmatter(\n      fileNode.internal.contentDigest,\n      content\n    )\n\n    deletePage(page)\n    createPage({\n      ...page,\n      context: {\n        ...page.context,\n        frontmatter,\n      },\n    })","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-mdx/src/gatsby-node.ts#L331-L367","documentation":"Thrown by gatsby-plugin-mdx's onCreatePage handler when the page's MDX content path (extracted via getPathToContentComponent) does not match any File node's absolutePath in the Gatsby node store. The plugin needs the File node to read frontmatter and re-create the page with context, so a missing node aborts the per-page processing.","triggerScenarios":"A page whose component string carries __contentFilePath pointing at an MDX file that has no corresponding File node — file was not sourced (no gatsby-source-filesystem covering it), path is stale (file moved/deleted after page creation), or absolutePath casing differs from what the page stores.","commonSituations":"MDX file deleted or moved after createPage ran but before the page is processed; gatsby-source-filesystem config does not include the directory holding the MDX; path case mismatch on case-sensitive filesystems; symlinked content directories not followed by the source plugin.","solutions":["Confirm the MDX file at mdxPath (printed in the message) still exists on disk.","Ensure gatsby-source-filesystem includes the directory containing that MDX so a File node is created.","If the path is stale, clear .cache and re-run `gatsby develop`/`build` so pages regenerate from current files.","Check for case mismatches between the page component path and the actual filename on disk."],"exampleFix":"// gatsby-config.js — before (MDX dir not sourced)\nplugins: [{ resolve: 'gatsby-source-filesystem', options: { name: 'posts', path: 'content/posts' } }]\n// after (include the MDX directory referenced by the page)\nplugins: [\n  { resolve: 'gatsby-source-filesystem', options: { name: 'posts', path: 'content/posts' } },\n  { resolve: 'gatsby-source-filesystem', options: { name: 'pages', path: 'src/pages' } },\n]","handlingStrategy":"validation","validationCode":"const fileNode = getNodesByType('File').find(n => n.absolutePath === mdxPath)\nif (!fileNode) { report.warn(`No File node for ${mdxPath}; skipping page`); return }","typeGuard":"const hasFileNode = (mdxPath: string): boolean =>\n  !!getNodesByType('File').find(n => n.absolutePath === mdxPath)","tryCatchPattern":null,"preventionTips":["Ensure gatsby-source-filesystem covers the MDX directory.","Clear .cache when MDX files move.","Match filename case exactly on case-sensitive filesystems."],"tags":["gatsby-plugin-mdx","file-node","source-filesystem","mdx"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}