Skip to content

fix(dev): show cwd-relative paths in the error page on Windows - #4705

Merged
pi0 merged 2 commits into
nitrojs:mainfrom
kaanisthatyou:fix/dev-error-windows-paths
Oct 3, 2026
Merged

pi0 merged 2 commits into
nitrojs:mainfrom
kaanisthatyou:fix/dev-error-windows-paths

Conversation

@kaanisthatyou

Copy link
Copy Markdown
Contributor

🔗 Linked issue

No issue; found while running the new dev error page (#4699) on Windows.

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

On Windows, app frames in the dev error page and in the [request error] terminal output keep their absolute path (C:/Users/me/app/server/routes/boom.ts:4:9) instead of ./server/routes/boom.ts:4:9. relativePath compares the frame path with process.cwd() as plain strings, but the cwd uses \ while Vite reports module paths with /, so the prefix never matches. This PR compares with / separators when the cwd is a Windows path.

The new unit test mocks process.cwd() as C:\app and checks both separators; it fails on main. In the playground on Windows with a throwing route, main prints at explode (C:/Users/.../playground/server/routes/boom.ts:4:9) and this branch prints at explode (./server/routes/boom.ts:4:9). The four dev-error-render tests that failed on Windows now pass.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

`relativePath` compared frame paths with `process.cwd()` as plain
strings. On Windows the cwd uses `\` while Vite reports module paths
with `/`, so app frames in the dev error page and the terminal output
kept their absolute `C:/...` path instead of `./server/...`.

Compare with `/` separators when the cwd is a Windows path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaanisthatyou
kaanisthatyou requested a review from pi0 as a code owner October 3, 2026 13:55
@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

@kaanisthatyou is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 48c58268-002d-4548-aedc-ea72e1370a5c
📥 Commits

Reviewing files that changed from the base of the PR and between a12a72d and 72d466c.

📒 Files selected for processing (2)
  • src/runtime/internal/error/_stack.ts
  • test/unit/dev-error-stack.test.ts
 __________________________________________________________
< This abstraction leaks more than a sieve in a rainstorm. >
 ----------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9568be16-8625-4489-bba7-9bf27a741a9e
📥 Commits

Reviewing files that changed from the base of the PR and between ae6516f and a12a72d.

📒 Files selected for processing (2)
  • src/runtime/internal/error/_stack.ts
  • test/unit/dev-error-stack.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

relativePath now returns the input unchanged when the working directory is unavailable. For Windows paths, it normalizes separators before checking whether the path is inside the working directory. Tests cover inside and outside paths.

Changes

Relative path handling

Layer / File(s) Summary
Normalize and test relative paths
src/runtime/internal/error/_stack.ts, test/unit/dev-error-stack.test.ts
relativePath handles an unavailable working directory and normalizes Windows separators when checking path boundaries. Tests cover paths inside the working directory, outside it, with a matching directory prefix, and on another drive.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to a12a7

Windows error paths can be shown relative to the working directory, while paths outside it remain unchanged. No merge-blocking issue is identified.

Architecture Summary

Architecture risk: 🔵 Low · up to a12a7

The change affects 2 systems.

Changed systems: src, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/runtime/internal/error/_stack.ts: relativePath now returns file immediately if no working directory is available. For Windows-style working directories, it normalizes separators in both paths before checking for a working-directory prefix followed by /; matching paths are made relative, while nonmatching paths fall through unchanged. This replaces the prior direct prefix check that accepted either slash at the boundary.
  • observed — Modified behavior in test/unit/dev-error-stack.test.ts: The test imports add afterEach, vi, and relativePath to support the new path tests.
  • observed — Modified behavior in test/unit/dev-error-stack.test.ts: Adds relativePath tests that mock the working directory and restore mocks after each test. They verify shortening for paths inside the working directory on POSIX and Windows, accepting either Windows separator; paths outside it, with a merely matching directory prefix, or on another drive remain unchanged.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the Conventional Commits format with the fix type and dev scope. It clearly describes the Windows path fix.
Description check ✅ Passed The description explains the Windows path mismatch, the intended fix, and the related tests. It is relevant to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4705

commit: a12a72d

@pi0
pi0 merged commit c26dca4 into nitrojs:main Oct 3, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants