fix: use loc.file from rollup errors if available#19222
Merged
patak-cat merged 1 commit intovitejs:mainfrom Jan 23, 2025
Merged
fix: use loc.file from rollup errors if available#19222patak-cat merged 1 commit intovitejs:mainfrom
patak-cat merged 1 commit intovitejs:mainfrom
Conversation
6c5fd7f to
43b5043
Compare
The loc.file references the file where the error occurred (containing the displayed line and column), rather than e.id which is the module.
43b5043 to
709c291
Compare
hi-ogawa
approved these changes
Jan 19, 2025
Contributor
hi-ogawa
left a comment
There was a problem hiding this comment.
Makes sense 👍
It looks like error overlay simply does err.loc?.file || err.id, but showing both seems nice too.
vite/packages/vite/src/client/overlay.ts
Lines 228 to 230 in 3395c19
patak-cat
approved these changes
Jan 20, 2025
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.
Description
Currently, Rollup errors output a filename that is actually the module name rather than the file where the error occurred. In the case of less, which supports imports, this can mean that the incorrect filename is output. Also note that the line and column numbers output are, in this case, not from the outputted file (confusing!).
This PR adds detection of
loc.fileand uses that in preference to the module id (although I've also included it for completeness).Example
Here is an example of the error message prior to this PR. The file identified is the module / entrypoint rather than the actual file:
Here is an example of the error message with this PR, note that the correct filename is identified: