Skip to content

Handle typescript errors in react-error-overlay #7091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react-error-overlay/src/utils/parseCompileError.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ErrorLocation = {|
colNumber?: number,
|};

const filePathRegex = /^\.(\/[^/\n ]+)+\.[^/\n ]+$/;
const filePathRegex = /^(?:\.|[A-Z]:)?(\/[^/\n ]+)+\.[^/\n ]+$/;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex should match both relative and absolute paths on all platforms.
(?:\.|[A-Z]:)? defines an optional non-capturing group which may contain either a period (for matching relative paths) or a Windows drive letter for matching absolute paths. I verified that Windows does not support drive letters after Z.
Unix absolute paths (/path/to/folder) are also matched correctly as the first group is optional.


const lineNumberRegexes = [
// Babel syntax errors
Expand All @@ -18,6 +18,10 @@ const lineNumberRegexes = [
// ESLint errors
// Based on eslintFormatter in react-dev-utils
/^Line (\d+):.+$/,

// TypeScript errors
// Based on typescriptFormatter in react-dev-utils
/^.*\((\d+),(\d+)\):$/,
];

// Based on error formatting of webpack
Expand Down