gatsbyjs/gatsby · error

Invalid RegEx: ${object[propName]}

Error message

Invalid RegEx: ${object[propName]}

What it means

Option-normalization warning in gatsby-remark-prismjs's replaceStringWithRegex helper: a plugin option expected as a RegExp is a plain string, but constructing a RegExp from it threw (invalid pattern). The option keeps its raw string value, so that pattern simply never matches; recursion continues over nested option objects.

Source

Thrown at packages/gatsby-remark-prismjs/src/replace-string-with-regexp.js:7

module.exports = function replaceStringWithRegex(object) {
  Object.keys(object).forEach(propName => {
    if (typeof object[propName] === `string`) {
      try {
        object[propName] = new RegExp(object[propName])
      } catch (e) {
        console.warn(`Invalid RegEx: `, object[propName])
      }
    }

    if (
      object[propName] instanceof Object &&
      !(object[propName] instanceof Array)
    ) {
      object[propName] = replaceStringWithRegex(object[propName])
    }
  })

  return object
}

View on GitHub (pinned to e85d62f177)

Solutions

  1. Fix the invalid regex syntax in the option value
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/gatsby-remark-prismjs/src/replace-string-with-regexp.js:7 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/2c045179a57184d3. Report an issue: GitHub.