-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
improve ERR_REQUIRE_ESM error reports by including root cause exception report. #4675
Comments
updated build environment fixed some bother, filed mochajs/mocha#4675 noted istanbuljs/nyc#1381 but no dice
@GerHobbelt makes total sense. Thanks! I'll try it out in the coming days and try and figure it out how to incorporate two errors in one 😁. My 2c on ESM migration (and totally off topic!): I actually think that the design of ESM in Node.js was (mostly) correct, and their insistence on keeping with the spec and not deviating from it will in the long run be a good thing. Even in the short run, keeping ESM async (and thus making the migration from sync CJS difficult) enables things like top-level await. I believe in the future this will also enable optimizations like faster loads, and importing from HTTP (a-la deno). So, yes, tough migration is coming in the next 1-2 years, but the end result will be a better (and standards-compliant) ecosystem. |
@GerHobbelt just to make sure that I understand the problem, can you create a repo that reproduces this problem, or at least a very detailed description of the problem, so that I have something to work with? |
@giltayar: thanks for the quick response & here's a little repo to play with: https://github.com/GerHobbelt/mocha-PoC-4675 |
Is your feature request related to a problem or a nice-to-have??
/Problem/! Saving time & money when the shit hits fan.
Actual scenario:
node v16, mocha 9.0.2, + custom markdown-it-footnote derivative under test -- which' code uses all
import
s, zerorequire
s. Worked with mocha 9.0.1 for a while.Confusing and /wrong/ error report by mocha 9.0.2:
After some serious WTF?!?! we patched
mocha\lib\esm-utils.js
to find out and added one line in there immediately after thecatch
before the error location @ line 50:which gives us this very helpful information before mocha barfs a hairball as before:
This immediately gives us something to check: turns out there's a typo in the package.json. Problem fixed.
My suggestion
When dumping errors (and hint messages like you do), include the root cause exception message because this mocha failure is due to some code migration happening (the markdown-it plugin at hand) but is far removed from what you point at in the "helpful hint" about cjs/mjs/etc., which actually did cost us more time, rather than saving time.
Simply keep the original exception handy when the second attempt happens to fail and include it in the mocha error report so the end user can do their diagnostic work. In this particular example, having seen the initial exception error message, I can wholly ignore the follow-up error + hint as it'll be clear to me where to start looking then!
Post Mortem
I do realize the entire import vs require + npm situation is a horror show (bad design if you ask me, but this is way out of scope and we gotta play the cards we're dealt, sometimes): see related issues like #4652 (comment), which amazingly kicked us in the teeth at the CI but nowhere on the local dev machines (Windows based). That kind of context being given, and error diagnostics being a hard target generally speaking, this didn't help exactly as the mocha error report was quite misleading in this case.
The text was updated successfully, but these errors were encountered: