nextjs - ✅(Solved) Fix App route code generation: path separator regex missing global flag causes build failure on Windows with nested routes [1 pull requests, 1 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#91312Fetched 2026-04-08 02:02:19
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Root Cause

  • Root cause: create-app-route-code.ts#L36 uses /[\\/]/ (no g) instead of /\\/g or normalizePathSep
  • Every other path separator normalisation in the codebase uses normalizePathSep or /\\/g
  • Fix already submitted in PR #91311: replaces the inline regex with the existing normalizePathSep utility (same approach used in the sibling index.ts at line 45)
  • Previous issue #91310 was auto-closed for missing reproduction link

Fix Action

Fixed

PR fix notes

PR #91311: fix: use normalizePathSep for app route path normalization

Description (problem / solution / changelog)

What?

Fixes the path separator normalization in create-app-route-code.ts where the regex /[\\/]/ was missing the global (g) flag, causing only the first backslash to be replaced on Windows.

Why?

On Windows, pagePath arrives with backslash separators (e.g., app\api\nested\route). Without the g flag, String.prototype.replace only replaces the first occurrence, producing app/api\nested\route instead of app/api/nested/route. This causes resolveAppRoute to fail for any nested app route.

Every other path separator normalization in the codebase uses either /\\/g (with global flag) or the normalizePathSep utility. This was the only instance missing the global flag.

How?

Replaced the buggy inline regex with the existing normalizePathSep utility from shared/lib/page-path/normalize-path-sep, which is already imported and used in the sibling index.ts file in the same loader directory.

fixes #91312

Checklist

  • Related issues linked using fixes #number
  • Tests added
  • Errors have a helpful link attached, see contributing.md
  • Linter, currentTests, TypeScript compiler passed

Changed files

  • packages/next/src/build/webpack/loaders/next-app-loader/create-app-route-code.ts (modified, +2/-1)

Code Example

const routePath = pagePath.replace(/[\\/]/, '/')
//                                   ^ no g flag — only first separator replaced

---

OS: Windows 11
Node.js: 20.x
Next.js: canary
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/ShehabSherif0/next-windows-app-route-repro

To Reproduce

  1. Clone https://github.com/ShehabSherif0/next-windows-app-route-repro on Windows
  2. npm install
  3. npm run build

The repo has a nested app route at app/api/nested/route.ts. On Windows the webpack loader receives the path as app\api\nested\route. The missing g flag on the replacement regex means only the first backslash is converted, causing resolveAppRoute to fail.

Current vs. Expected behavior

Current: create-app-route-code.ts line 36:

const routePath = pagePath.replace(/[\\/]/, '/')
//                                   ^ no g flag — only first separator replaced

On Windows with a nested route this produces app/api\nested\route instead of app/api/nested/route, breaking route resolution.

Expected: All backslashes normalised to forward slashes. The sibling file next-app-loader/index.ts already uses normalizePathSep for exactly this purpose; create-app-route-code.ts should too.

Provide environment information

OS: Windows 11
Node.js: 20.x
Next.js: canary

The bug is visible in the source regardless of Node/Next version — it is a missing g flag on a regex literal.

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

  • Root cause: create-app-route-code.ts#L36 uses /[\\/]/ (no g) instead of /\\/g or normalizePathSep
  • Every other path separator normalisation in the codebase uses normalizePathSep or /\\/g
  • Fix already submitted in PR #91311: replaces the inline regex with the existing normalizePathSep utility (same approach used in the sibling index.ts at line 45)
  • Previous issue #91310 was auto-closed for missing reproduction link

extent analysis

TL;DR

Replace the regex literal in create-app-route-code.ts with the existing normalizePathSep utility to normalize all path separators.

Guidance

  • Verify the issue by checking the routePath variable in create-app-route-code.ts on Windows with a nested route.
  • To fix, replace the line const routePath = pagePath.replace(/[\\/]/, '/') with const routePath = normalizePathSep(pagePath).
  • Check the sibling file next-app-loader/index.ts for reference, which already uses normalizePathSep for path separator normalization.
  • Test the fix by running npm run build and verifying that the route resolution works as expected.

Example

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

// After
const routePath = normalizePathSep(pagePath)

Notes

This fix assumes that the normalizePathSep utility is available and correctly implemented in the codebase.

Recommendation

Apply the workaround by replacing the regex literal with the normalizePathSep utility, as it is a more robust and consistent solution.

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