gatsbyjs/gatsby · error · Error
A RegExp instance is only valid for $regex and $glob compara
Error message
A RegExp instance is only valid for $regex and $glob comparators
What it means
Late-stage guard in getNodesFromCacheByValue: after special-cased operators, a filter value that is a RegExp appears under a comparator other than $regex/$glob. Since RegExp cannot be an index key, this is rejected — most likely an internal misuse of the cache API.
Source
Thrown at packages/gatsby/src/datastore/in-memory/indexing.ts:828
// Nothing is lt/gt null
return undefined
}
// This is an edge case and this value should be directly indexed
// For `lte`/`gte` this should only return nodes for `null`, not a "range"
return filterCache.byValue.get(filterValue)
}
if (Array.isArray(filterValue)) {
throw new Error(
"Array is an invalid filter value for the `" + op + "` comparator"
)
}
if (filterValue instanceof RegExp) {
// This is most likely an internal error, although it is possible for
// users to talk to this API more directly.
throw new Error(
`A RegExp instance is only valid for $regex and $glob comparators`
)
}
if (op === `$lt`) {
// First try a direct approach. If a value is queried that also exists then
// we can prevent a binary search through the whole list, O(1) vs O(log n)
const ranges = filterCache.meta.valueRangesAsc
const nodes = filterCache.meta.nodesByValueAsc
const range = ranges!.get(filterValue)
if (range) {
const arr = nodes!.slice(0, range[0])
arr.sort(sortByIds)
// elemMatch can cause a node to appear in multiple buckets so we must dedupe
if (wasElemMatch) {
expensiveDedupeInline(arr)View on GitHub (pinned to e85d62f177)
Solutions
- Use RegExp values only with $regex or $glob comparators
- Convert regex intentions to a $regex filter statement
- Report as a Gatsby bug if it occurs with a plain GraphQL query
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/gatsby/src/datastore/in-memory/indexing.ts:828 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/e97b73ef561fcacf.
Report an issue: GitHub.