-
-
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
Fix: wrong error thrown while loading reporter #4842
Conversation
try { | ||
reporter = require(reporterName); | ||
foundReporter = require.resolve(reporterName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juergba this line caused a warning when trying to bundle mocha/mocha.js
using webpack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AviVahl This one: Critical dependency: the request of a dependency is an expression
?
Is this a problem? I need to check wether the module exists, and I can't use a fs
function either.
In a browser environment we shouldn't get up to this line anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly that one.
The warning actually broke several internal projects we have that bundle mocha into the browser. There was infra code there that verified no errors/warnings from bundling.
If the branch is node-specific, would it be possible to completely separate it out of the browser bundle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I achieve this, exclude a specific code block from the bundle?
Btw the transpiled ES5 bundle (mocha.js) will be dropped in a few weeks, and the ES2018 bundle (mocha-es2018.js renamed to mocha.js) will be the one and only. If you have any input, would be welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can think of several possible ways to achieve this.
I usually separate the isomorphic parts of code from the Node-specific parts.
So: the cli, config loading, reporter loading, dynamic require
/require.resolve
, etc would all belong to the Node-specific part.
The mocha.js
bundle would only include the runner itself and associated APIs.
Another, perhaps trickier, way to achieve this is to specify "browser": { "./my-node-specific-file.js": null}
which would cause bundlers to skip that file and inject an empty object instead. Runtime checks would be needed to protect against the replaced API.
Regarding es2018? My team welcomes this change. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue is present even now in v10. Have you found a solution @AviVahl ? I can supress these errors in webpack config but it doesn't seem like the right solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've stopped bundling mocha from our end because of the many bundling regressions it exhibited across the years/versions. Our tool (mocha-play) uses the prebuilt bundle (in the npm package) and injects it to the page.
Description
When developing a third-party reporter, Mocha misdiagnoses an error coming from within the reporter as the reporter module not being found.
Description of the Change
reporter()
when used programmatically via Mocha APIApplicable issues
closes #3596