nextjs - 💡(How to fix) Fix App route code generation: path separator regex missing global flag on Windows [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#91310Fetched 2026-04-08 02:02:21
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Root Cause

  1. Use Windows
  2. Create a deeply nested app route (e.g., app/api/nested/route.ts)
  3. The pagePath parameter arrives with backslash separators on Windows (e.g., app\api\nested\route)
  4. The regex /[\\/]/ (without the g flag) only replaces the first separator, producing app/api\nested\route instead of app/api/nested/route
  5. resolveAppRoute fails because the partially-normalized path doesn't match
RAW_BUFFERClick to expand / collapse

Link to the code that causes this issue

https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/loaders/next-app-loader/create-app-route-code.ts#L36

To Reproduce

  1. Use Windows
  2. Create a deeply nested app route (e.g., app/api/nested/route.ts)
  3. The pagePath parameter arrives with backslash separators on Windows (e.g., app\api\nested\route)
  4. The regex /[\\/]/ (without the g flag) only replaces the first separator, producing app/api\nested\route instead of app/api/nested/route
  5. resolveAppRoute fails because the partially-normalized path doesn't match

Current vs. Expected behavior

Current: pagePath.replace(/[\\/]/, '/') replaces only the first backslash, leaving subsequent backslashes intact.

Expected: All backslashes should be normalized to forward slashes.

Provide environment information

N/A - bug is visible in source code. The regex /[\\/]/ is missing the global (g) flag.

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

App Router

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

next build (default)

Additional context

The sibling file next-app-loader/index.ts (line 45) already imports and uses the normalizePathSep utility for the same purpose. Every other path separator normalization in the codebase uses either /\\/g (with global flag) or the normalizePathSep utility. This is the only instance missing the global flag.

extent analysis

TL;DR

  • Adding the global flag to the regex /[\\/]/g will likely fix the issue by replacing all backslashes with forward slashes.

Guidance

  • Review the create-app-route-code.ts file and update the pagePath.replace(/[\\/]/, '/') line to pagePath.replace(/[\\/]/g, '/') to ensure all backslashes are replaced.
  • Verify the fix by creating a deeply nested app route on Windows and checking that the pagePath parameter is correctly normalized to use only forward slashes.
  • Consider using the normalizePathSep utility, already used in other parts of the codebase, for consistency and to avoid similar issues in the future.
  • Test the updated code with various nested route scenarios to ensure the fix does not introduce any new issues.

Example

// Before
const normalizedPath = pagePath.replace(/[\\/]/, '/');

// After
const normalizedPath = pagePath.replace(/[\\/]/g, '/');

Notes

  • This fix assumes that the issue is solely due to the missing global flag in the regex, as implied by the provided context.
  • The use of the normalizePathSep utility might be a better long-term solution for consistency across the codebase.

Recommendation

  • Apply workaround: Add the global flag to the regex to replace all backslashes, as this directly addresses the identified issue and is a straightforward fix.

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

nextjs - 💡(How to fix) Fix App route code generation: path separator regex missing global flag on Windows [1 comments, 2 participants]