Skip to content

Throw better error messages for parse errors in non-JS files - #2466

Merged
lukastaegert merged 1 commit into
masterfrom
better-json-error
Sep 21, 2018
Merged

Throw better error messages for parse errors in non-JS files#2466
lukastaegert merged 1 commit into
masterfrom
better-json-error

Conversation

@lukastaegert

Copy link
Copy Markdown
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

One of the most common gotchas which quickly leads to people despairing is if one of their dependencies (or they themselves) imports a JSON file which leads to a syntax error, cf. e.g. #1652.

This patch subtly improves our error messages by checking for PARSE_ERRRORs whether they happened in a file with an extension that does not end with "js" (to catch both .js and .mjs). If so, the error message reads either

Unexpected token (Note that you need plugins to import files that are not JavaScript)

or

Unexpected token (Note that you need rollup-plugin-json to import JSON files)

specifically for .json files. Feedback e.g. on the wording of the messages is very much welcome!

@shellscape shellscape left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@lukastaegert
lukastaegert merged commit bfb6b03 into master Sep 21, 2018
@lukastaegert
lukastaegert deleted the better-json-error branch September 21, 2018 04:14
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