-
Notifications
You must be signed in to change notification settings - Fork 779
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(utils): fix warning thrown by Webpack #2843
fix(utils): fix warning thrown by Webpack #2843
Conversation
Fixes a warning thrown by Webpack for using "require" without importing anything. Warning reads "require function is used in a way in which dependencies cannot be statically extracted" Closes issue dequelabs#2840
d907879
to
8a68a82
Compare
@@ -24,7 +24,7 @@ if (!_rng && _crypto && _crypto.getRandomValues) { | |||
} | |||
|
|||
try { | |||
if (!_rng && require) { | |||
if (!_rng) { |
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 change worries me. How does this change effect other supported environments?
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.
Before, if require
wasn't defined, it would skip the conditional and continue on. Now, if require
isn't defined, an error will be thrown by require('crypto')
on the next line, which will be caught by the try/catch block. I don't think this changes the execution in a meaningful way
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.
Thanks for the explanation.
@WilcoFiers please merge if you are ok with this too |
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.
Thanks for the pull request. Yeah this makes sense.
Fixes a warning thrown by Webpack for using "require" without importing anything. Warning reads "require function is used in a way in which dependencies cannot be statically extracted" Closes issue #2840
#2840 (comment)
This PR updates a line added in the recent 4.1.3 release. Webpack is throwing a warning when this library is included in a bundle, pointed at the given line.
I believe what's happening here is that Webpack sees the word "require", but doesn't understand that it's not being used to actually "require" something. Webpack doesn't know what to do with it, so it throws a warning.
The line is already wrapped in a try, so it should be fine to just drop the
&& require
in the condition. Ifconst nodeCrypto = require('crypto')
fails, the error will get caught and we can continue on.Closes issue: #2840