Show where syntax error from with ESM #4558
Closed
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 of the Change
This is a kind of hack because node.js currently not support syntax errors in detail. See nodejs/node#49441
And This is another approach to #4557 .
I found
node --unhandled-rejections=throw -e "import('syntax-error-file.mjs')"
show syntax erroed file, linenumber, and code.So, I try to run it with a file to import only when
SyntaxError
raised.So, it will show like this:
And
--unhandled-rejections=throw
is default since Node.js 15.0.0Alternate Designs
See #4557
Why should this be in core?
Before node.js itself support it, Users can find easily where a syntax error from.
Possible Drawbacks
It can be broken when Node.js itself supports it.
Applicable issues
close #4551
If we agreed with this approach, I will add tests for It.
I want to hear your opinion about this workaround.