vercel/next.js · error · Error

You cannot define a route with the same specificity as a opt

Error message

You cannot define a route with the same specificity as a optional catch-all route ("${r}" and "${r}[[...${this.optionalRestSlugName}]]").

What it means

During route-tree sorting (_smoosh in SortedRoutes), a directory level that contains an optional catch-all [[...slug]] cannot also define a plain route at that same level: the optional catch-all already matches the exact path, producing ambiguous duplicate specificity. Fires while validating pages-router file routes at build/dev time.

Source

Thrown at packages/next/src/shared/lib/router/utils/sorted-routes.ts:41

    }
    if (this.optionalRestSlugName !== null) {
      childrenPaths.splice(childrenPaths.indexOf('[[...]]'), 1)
    }

    const routes = childrenPaths
      .map((c) => this.children.get(c)!._smoosh(`${prefix}${c}/`))
      .reduce((prev, curr) => [...prev, ...curr], [])

    if (this.slugName !== null) {
      routes.push(
        ...this.children.get('[]')!._smoosh(`${prefix}[${this.slugName}]/`)
      )
    }

    if (!this.placeholder) {
      const r = prefix === '/' ? '/' : prefix.slice(0, -1)
      if (this.optionalRestSlugName != null) {
        throw new Error(
          `You cannot define a route with the same specificity as a optional catch-all route ("${r}" and "${r}[[...${this.optionalRestSlugName}]]").`
        )
      }

      routes.unshift(r)
    }

    if (this.restSlugName !== null) {
      routes.push(
        ...this.children
          .get('[...]')!
          ._smoosh(`${prefix}[...${this.restSlugName}]/`)
      )
    }

    if (this.optionalRestSlugName !== null) {
      routes.push(
        ...this.children

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Remove the duplicate route that conflicts with the optional catch-all route.
Defensive patterns

Strategy: validation

When it happens

Trigger: A route conflicts with an optional catch-all route at the same specificity.

Common situations: Defining both a static route and an [[...slug]] route that would match the same paths.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/212b5cabbc8b9036. Report an issue: GitHub.