gatsbyjs/gatsby · error · Error

The following page component must contain '${CONTENT_FILE_PA

Error message

The following page component must contain '${CONTENT_FILE_PATH_QUERY}':
${cleanedComponentPath}

What it means

splitComponentPath only understands the ?__contentFilePath= marker for MDX-style split component paths; after cleaning trailing export=... suffixes it expects exactly two segments. More than one CONTENT_FILE_PATH_QUERY occurrence (or malformed input) violates that invariant and throws, naming the offending cleaned path.

Source

Thrown at packages/gatsby-core-utils/src/parse-component-path.ts:23

const CONTENT_FILE_PATH_QUERY = `?__contentFilePath=`

// Split the path component URI without using the expensive URI.parse()
export const splitComponentPath = (componentPath: string): Array<string> => {
  // If the path does not include the contentFilePath query, we can assume its a regular path
  if (!componentPath.includes(CONTENT_FILE_PATH_QUERY)) {
    return [componentPath]
  }

  const cleanedComponentPath = componentPath.replace(
    /&export=(default|head)$/,
    ``
  )
  const splitPath = cleanedComponentPath.split(CONTENT_FILE_PATH_QUERY)

  // We only support URI paths with the `?__contentFilePath=` parameter
  if (splitPath.length !== 2) {
    throw new Error(
      `The following page component must contain '${CONTENT_FILE_PATH_QUERY}':\n${cleanedComponentPath}`
    )
  }

  return splitPath
}

// Get the path to the actual js page component
export const getPathToLayoutComponent = (componentPath: string): string =>
  splitComponentPath(componentPath)[0]

// Get the path to the content file, falling back to the js component if no content file is given.
// Pages directly created from `.mdx` files
export const getPathToContentComponent = (componentPath: string): string => {
  const splitPath = splitComponentPath(componentPath)
  if (splitPath.length === 1) {
    return splitPath[0]
  }

View on GitHub (pinned to e85d62f177)

Solutions

  1. Use at most one ?__contentFilePath= query in the component path
  2. Check createPage calls that assemble component paths programmatically for duplicated query strings
  3. Pass the mdx body and component as separate fields instead of a concatenated string
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/gatsby-core-utils/src/parse-component-path.ts:23 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gatsbyjs/gatsby@e85d62f177 (2026-08-26). Data as JSON: /api/errors/cd3d4861e232da92. Report an issue: GitHub.