vercel/next.js · error · Error
Failed to resolve pattern "${patterns.join(',')}": ${error.m
Error message
Failed to resolve pattern "${patterns.join(',')}": ${error.message} What it means
Thrown by resolveBuildPaths() when the underlying glob library rejects the combined include pattern while resolving build paths for the App/Pages routers. Next.js wraps the glob error to surface which pattern(s) failed so you can correct the path spec. It fires during build/dev startup when Next.js enumerates route files from user-supplied or default path patterns.
Source
Thrown at packages/next/src/lib/resolve-build-paths.ts:100
: `{${includePatterns.join(',')}}`
try {
const matches = (await glob(combinedPattern, {
cwd: projectDir,
ignore: excludePatterns,
})) as string[]
if (matches.length === 0) {
Log.warn(`Pattern "${patterns.join(',')}" did not match any files`)
}
for (const file of matches) {
if (!fs.statSync(path.join(projectDir, file)).isDirectory()) {
categorizeAndAddPath(file, appPaths, pagePaths, validFileMatcher)
}
}
} catch (error) {
throw new Error(
`Failed to resolve pattern "${patterns.join(',')}": ${
isError(error) ? error.message : String(error)
}`
)
}
return {
appPaths: Array.from(appPaths).sort(),
pagePaths: Array.from(pagePaths).sort(),
}
}
/**
* When the project keeps its `app/` or `pages/` directory under `src/`, prepend
* `src/` to bare patterns so the glob actually matches files on disk. Patterns
* that already include the `src/` prefix are returned unchanged.
*/
function addSrcPrefixIfNeeded(View on GitHub (pinned to 0ae8c72462)
Solutions
- Check the pattern printed in the message and validate it as a glob expression (balance braces, escape literal brackets/braces).
- If using dynamic-route segments in the pattern, ensure they are well-formed ([slug], [...slug], [[...slug]]) so escapeBrackets can process them.
- Reduce the pattern to a single include to isolate which entry breaks the combined {a,b} expansion.
- Run a standalone glob (e.g. via the 'glob' package) against projectDir to reproduce the parser error outside Next.js.
Example fix
// before resolveBuildPaths(['app/blog/[slug/page.tsx'], projectDir, pageExtensions) // after (close the bracket) resolveBuildPaths(['app/blog/[slug]/page.tsx'], projectDir, pageExtensions)
Defensive patterns
Strategy: validation
Validate before calling
import globOriginal from 'next/dist/compiled/glob'
import { promisify } from 'util'
const glob = promisify(globOriginal)
async function validatePattern(pattern, cwd) {
try { await glob(pattern, { cwd }) }
catch (e) { throw new Error(`Pattern '${pattern}' is invalid: ${e.message}`) }
} Type guard
function isValidGlob(p: string): boolean {
// basic brace/bracket balance check
let braces = 0, brackets = 0
for (const ch of p) {
if (ch === '{') braces++
if (ch === '}') braces--
if (ch === '[') brackets++
if (ch === ']') brackets--
if (braces < 0 || brackets < 0) return false
}
return braces === 0 && brackets === 0
} Try / catch
try {
const paths = await resolveBuildPaths(patterns, projectDir, pageExtensions)
} catch (err) {
if (err.message.startsWith('Failed to resolve pattern')) {
// log pattern, fall back to default file discovery
}
throw err
} Prevention
- Validate glob patterns with a standalone glob call before passing to resolveBuildPaths.
- Keep dynamic-route segments well-formed so escapeBrackets can process them.
- Avoid hand-building brace-expanded combined patterns; pass individual patterns to the API.
When it happens
Trigger: Calling resolveBuildPaths() with a malformed glob pattern (e.g. unbalanced braces, invalid brace-expansion like '{a,b', or a pattern with illegal characters). Also triggered when escapeBrackets() or addSrcPrefixIfNeeded() produce a combined pattern that the compiled glob library cannot parse.
Common situations: A dynamic-route bracket pattern that was not escaped correctly, a typo in a comma-separated path list fed to the build, or an upgrade that changed how brace expansion is combined (the code joins multiple includes via {p1,p2}). Rare in normal projects; more likely in custom tooling or after editing app/pages directory structure.
Related errors
- NEXT_EXPORT_ERROR
- The provided export path '${pathname}' doesn't match the '${
- > Couldn't find any `pages` or `app` directory. Please creat
- > `pages` and `app` directories should be under the same fol
- The key "${key}" under "env" in ${config.configFileName || '
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/d0cb673aa20fcb4b.
Report an issue: GitHub.