gatsbyjs/gatsby · warning

An error occurred building the slug parts. This is likely a

Error message

An error occurred building the slug parts. This is likely a bug within Gatsby and not your code. Please report it to us if you run into this.

What it means

path-utils.ts extractAllCollectionSegments runs the regex /\{.*?\}/g on an absolute path to pull out every {Model.field} token. The match returns null when there are no curly-brace segments at all. Because this function is only called on paths already classified as collection paths, a null result signals an internal inconsistency the user cannot cause through normal config - hence the message asks the user to report it as a Gatsby bug.

Source

Thrown at packages/gatsby-plugin-page-creator/src/path-utils.ts:42

}

// Remove trailing slash
export function stripTrailingSlash(str: string): string {
  return str.endsWith(`/`) ? str.slice(0, -1) : str
}

const curlyBracesContentsRegex = /\{.*?\}/g

// This extracts all information in an absolute path to an array of each collection part
// /foo/{Model.bar}/{Model.baz} => ['Model.bar', 'Model.baz']
export function extractAllCollectionSegments(
  absolutePath: string
): Array<string> {
  const slugParts = absolutePath.match(curlyBracesContentsRegex)

  // This shouldn't happen - but TS requires us to validate
  if (!slugParts) {
    throw new Error(
      `An error occurred building the slug parts. This is likely a bug within Gatsby and not your code. Please report it to us if you run into this.`
    )
  }

  return slugParts
}

const extractFieldWithoutUnionRegex = /\(.*\)__/g

/**
 * Given a filePath part that is a collection marker it do this transformation:
 * @param {string} filePart - The individual part of the URL
 * @returns {Array<string>} - Returns an array of extracted fields (with converted "Unions")
 * @example
 * {Model.bar} => bar
 * {Model.field__bar} => field__bar
 * {Model.field__(Union)__bar} => field__bar
 */

View on GitHub (pinned to 8b06340921)

Solutions

  1. Update to the latest patch of gatsby and gatsby-plugin-page-creator; this path is internal and bugs are fixed upstream.
  2. Remove or simplify any custom code that rewrites node/file paths in onCreateNode or onCreatePage.
  3. If reproducible, file a Gatsby issue with the exact file path, OS, and package versions.
  4. As a workaround, rename the file so it does not use a collection segment, or move it out of src/pages and create the page manually via createPage.
Defensive patterns

Strategy: try-catch

Validate before calling

function safeExtractSegments(absolutePath) {
  const m = absolutePath.match(/\{.*?\}/g);
  if (!m) return []; // graceful: treat as non-collection instead of throwing
  return m;
}

Type guard

function hasCollectionSegment(absolutePath) {
  return /\{.*?\}/.test(absolutePath);
}

Try / catch

try {
  const segments = extractAllCollectionSegments(absolutePath);
} catch (e) {
  // This path is documented as an internal Gatsby bug; fall back to treating
  // the path as a normal (non-collection) page and report upstream.
  reporter.warn(`Skipping collection extraction for ${absolutePath}: ${e.message}`);
}

Prevention

When it happens

Trigger: Internal: the page-creator's classification step decided a path is a collection path (e.g. it contained a brace at one stage) but by the time extractAllCollectionSegments runs the braces are gone - typically through path normalization, symlinks, or a transform that stripped characters. Effectively unreachable through normal user input.

Common situations: Rare. Has appeared after upgrades that changed path handling, with unusual filesystems (Windows UNC paths), or when a custom onCreateNode mutates the absolute path. If a user sees it, it is almost always a Gatsby regression worth reporting with a reproduction.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/00b5752530e79b12. Report an issue: GitHub.