nextjs - 💡(How to fix) Fix Next.js Incorrectly Detects Routing Conflict Between [id] and [projectId] [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85865Fetched 2026-04-08 02:13:34
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
1
Timeline (top)
commented ×1issue_type_added ×1labeled ×1

Error Message

  1. Next.js reports the routing conflict error and server fails to start
  • Next.js Version: 14.2.32 (also tested with 16.0.1 - error persists)
  • Error persists
  • Updated to Next.js 16.0.1 - error persists
  • Downgraded to 14.2.32 - error persists
  • Removed [id].ts file - error persists (issue is with [id]/ directory)
  • Error occurs during route tree construction in Next.js
  • Error persists
  • The error occurs in Next.js's internal route sorting/validation logic (sorted-routes.js)
  • Impact: Application cannot start - returns 500 Internal Server Error This might be related to how Next.js handles nested dynamic routes or route tree construction. The error suggests Next.js is incorrectly identifying route conflicts during the route sorting/validation phase.
  • The error persists even when [id].ts is removed, indicating the issue is specifically with the [id]/ directory structure

Fix Action

Fix / Workaround

  • Severity: Critical
  • Impact: Application cannot start - returns 500 Internal Server Error
  • Workaround: None found yet

Note: This bug prevents the application from starting, making it impossible to use Next.js with this route structure. Any help or workaround would be greatly appreciated.

Code Example

pages/api/projects/
     ├── [id].ts
     └── [id]/
         ├── bookmark.ts
         ├── fund.ts
         ├── funding-progress.ts
         ├── milestones.ts
         └── governance/
             └── proposals.ts
2. Run `npm run dev`

3. Next.js reports the routing conflict error and server fails to start

### Current vs. Expected behavior

## Expected Behavior

Next.js should accept this route structure:
- `pages/api/projects/[id].ts` - handles `/api/projects/[id]`
- `pages/api/projects/[id]/` - handles `/api/projects/[id]/...`

This is a valid Next.js route structure and should not cause conflicts.

## Actual Behavior

Next.js incorrectly detects a conflict between `[id]` and `[projectId]` and crashes during server startup, preventing the application from running.

### Provide environment information

---

### Which area(s) are affected? (Select all that apply)

Pages Router

### Which stage(s) are affected? (Select all that apply)

next dev (local)

### Additional context

## Route Structure

### Actual File System:
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/PhoenixWild29/empowergrid-project/tree/master

To Reproduce

  1. Create the following route structure:

    pages/api/projects/
      ├── [id].ts
      └── [id]/
          ├── bookmark.ts
          ├── fund.ts
          ├── funding-progress.ts
          ├── milestones.ts
          └── governance/
              └── proposals.ts
  2. Run npm run dev

  3. Next.js reports the routing conflict error and server fails to start

Current vs. Expected behavior

Expected Behavior

Next.js should accept this route structure:

  • pages/api/projects/[id].ts - handles /api/projects/[id]
  • pages/api/projects/[id]/ - handles /api/projects/[id]/...

This is a valid Next.js route structure and should not cause conflicts.

Actual Behavior

Next.js incorrectly detects a conflict between [id] and [projectId] and crashes during server startup, preventing the application from running.

Provide environment information

## Environment

- **Next.js Version:** 14.2.32 (also tested with 16.0.1 - error persists)
- **Node.js Version:** (please check with `node --version`)
- **Operating System:** Windows 10
- **Package Manager:** npm

Which area(s) are affected? (Select all that apply)

Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Route Structure

Actual File System:

pages/api/projects/
  ├── [id].ts                    ✅ EXISTS
  ├── [id]/                      ✅ EXISTS (directory)
  │   ├── bookmark.ts
  │   ├── fund.ts
  │   ├── funding-progress.ts
  │   ├── milestones.ts
  │   └── governance/
  │       └── proposals.ts
  ├── index.ts
  ├── compare.ts
  └── search/
      └── suggestions.ts

What Next.js Reports:

  • Next.js claims there's a conflict between [id] and [projectId] at the same path level
  • NO [projectId] file or directory exists in pages/api/projects/

Investigation Steps Taken

  1. Manual File System Check

    • Verified no [projectId] file or directory exists
    • Checked for hidden files
    • Verified file names are correct (no typos or hidden characters)
  2. Recreated Directory Structure

    • Deleted and recreated [id] directory
    • Restored all files
    • Error persists
  3. Next.js Version Testing

    • Updated to Next.js 16.0.1 - error persists
    • Downgraded to 14.2.32 - error persists
  4. Configuration Check

    • No route rewrites/redirects in next.config.js
    • No route-related configuration issues found
  5. Route File Analysis

    • No route files found that use both [id] and [projectId] patterns
    • No route files found that Next.js might be misinterpreting
  6. Isolation Testing

    • Removed [id].ts file - error persists (issue is with [id]/ directory)
    • Error occurs during route tree construction in Next.js
  7. Cache Clearing

    • Cleared .next directory
    • Cleared node_modules/.cache
    • Error persists

Additional Context

  • The error occurs in Next.js's internal route sorting/validation logic (sorted-routes.js)
  • The handleSlug function is detecting a conflict that doesn't exist in the actual file system
  • Other routes in the project use [projectId] in different paths (e.g., api/recommendations/similar/[projectId].ts), but they are in completely different directory structures and should not conflict

Impact

  • Severity: Critical
  • Impact: Application cannot start - returns 500 Internal Server Error
  • Workaround: None found yet

Possible Related Issues

This might be related to how Next.js handles nested dynamic routes or route tree construction. The error suggests Next.js is incorrectly identifying route conflicts during the route sorting/validation phase.

Additional Information

  • The error persists even when [id].ts is removed, indicating the issue is specifically with the [id]/ directory structure
  • No route rewrites, redirects, or other configuration that could cause this
  • File system has been manually verified multiple times

Note: This bug prevents the application from starting, making it impossible to use Next.js with this route structure. Any help or workaround would be greatly appreciated.

extent analysis

TL;DR

  • Rename the [id] directory to a different name to avoid conflicts with Next.js's internal route sorting/validation logic.

Guidance

  • Verify that there are no hidden files or directories in the pages/api/projects/ directory that could be causing the conflict.
  • Try renaming the [id] directory to a different name, such as [project-id], to see if the conflict resolves.
  • Check if there are any other routes in the project that use the same naming convention and could be causing the conflict.
  • Consider filing a bug report with Next.js if the issue persists after trying the above steps.

Example

  • No code snippet is provided as the issue is related to the file system structure and not a specific code block.

Notes

  • The issue seems to be related to how Next.js handles nested dynamic routes and route tree construction.
  • The error persists even when [id].ts is removed, indicating the issue is specifically with the [id]/ directory structure.
  • Renaming the [id] directory may resolve the conflict, but it's unclear why Next.js is detecting a conflict in the first place.

Recommendation

  • Apply workaround: Rename the [id] directory to a different name to avoid conflicts with Next.js's internal route sorting/validation logic. This is recommended because it's a simple and non-invasive change that may resolve the issue, and it allows the application to start and function as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING