Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Oct 9, 2025

Description

This PR adds server.forwardRuntimeLogs option, which enables forwarding unhandled runtime errors from browser to dev server and logs them on terminal.

I mostly ported Vitest's error reporting logic and it even bundles a part of @vitest/utils for stack trace parsing (the output below looks so familiar 😄). The code size is expected to be compact and proved to be robust, so I think this approach is fine.

I initially implemented in https://github.com/hi-ogawa/reproductions/tree/main/vite-20487-unhandled-error-to-console/runtime-log and userland plugin is possible (though with a caveat that ssr framework requires a way to inject script other than transformIndexHtml.)

TODO

  • test
  • docs
  • actually test with agent
  • discuss feature scope (maybe follow up)
    • naming things (currently it's vaguely named as server.forwardRuntimeLogs considering the future scope)
    • forward console.error? (e.g. react hydration error is not runtime but only console.error No, this wasn't the case.)
    • allow filter by error? some default we should filter out? (cf. vitest)
    • ssr runtime error? (global process.on like Vitest)
    • expose this via mcp server? (cf. Feat: get_errors MCP endpoint vercel/next.js#84161)
    • auto detect agent? (cf. https://github.com/search?q=%22process.env.CLAUDECODE%22&type=code)
    • should event type / payload considered public API? (should we adjust types to allow future extension without breaking change?)

Related plugins

Example

image

Example: Github Copilot fixing bug by checking server logs

https://github.com/hi-ogawa/reproductions/tree/main/vite-20916-demo

image

@hi-ogawa hi-ogawa marked this pull request as ready for review October 9, 2025 16:50
Copy link

pkg-pr-new bot commented Oct 10, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20916

commit: 0dc47db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant