fix(windows): add Express path-rewriting middleware for Next.js static exports#2
Open
khaira777 wants to merge 1 commit into
Open
fix(windows): add Express path-rewriting middleware for Next.js static exports#2khaira777 wants to merge 1 commit into
khaira777 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Problem
There is a severe Next.js routing bug affecting local Windows development. On Windows, Next.js static exports (
output: "export") use backslashes (\), which causes the build to generate nested directories (e.g.,__next.A\B\__PAGE__.txt) instead of the expected flat files (e.g.,__next.A.B.__PAGE__.txt).When the client router requests the flat file with dots, Windows Express fails to find it. Instead of throwing a 404, the catch-all route silently serves
index.htmlas a fallback. React attempts to parse this HTML as an RSC data payload and fails.The Symptom: Because the payload fails to parse, React aborts the navigation. The app gets "stuck" on the current screen. Clicking sidebar links does nothing without a hard manual refresh, effectively breaking SPA navigation for local Windows developers.
(Note: This does not affect the official GitHub releases because CI/CD runs on Linux runners, which correctly generate the flat files).
The Solution
Added a lightweight Express middleware to both
main/server.tsandmain/kds-server.ts.This middleware:
__next..fs.existsSync()to verify the nested Windows directory actually exists on disk.req.urlsoexpress.staticcan serve the correct chunk.Because of the
fs.existsSynccheck, this middleware is a safe "no-op" on Linux/macOS machines and will not interfere with production CI/CD builds.Testing
npm run buildandnpm run build:frontendto confirm no compilation errors were introduced.