-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Reading from "node:crypto" is not handled by webpack plugins #17
Comments
barbalex
changed the title
polyfilling crypto seems no more possible
polyfilling crypto no more possible?
Jul 21, 2021
2 tasks
barbalex
changed the title
polyfilling crypto no more possible?
Reading from "node:crypto" is not handled by (webpack) plugins
Jul 22, 2021
barbalex
changed the title
Reading from "node:crypto" is not handled by (webpack) plugins
Reading from "node:crypto" is not handled by webpack plugins
Jul 22, 2021
I know this is probably dead, but I'm encountering it now.. You can get around this, when using webpack at least, by using plugins: plugins: [
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
resource.request = resource.request.replace(/^node:/, "");
})
] |
Combining both answers for Gatsby I solved it by adding this to the
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In version 4.0.0, the import for crypto was changed from:
to:
See here.
I am surprised that it is not imported as:
The nodes docs (https://nodejs.org/api/crypto.html#crypto_class_hash) show this way for importing:
There may be a good reason for importing
node:crypto
I don't know - I am a frontend dev, not using node.js very often. I don't even know whatnode:crypto
really does and why it can be used in this way. It seems to explicitly declare to import the crypto module from node though.Anyway, I ran into a problem that seems to stem from this way of importing:
My app uses gatsby. Gatsby recently changed from webpack v4 to webpack v5. When updating md5-hex from 3.0.1 to 4.0.0 I get this error when building the app:
After some searching I found that md5-hex causes this (I had no idea what dependency called node:crypto). Then I found that webpack had polyfilled for node until version 4, no more in version 5 (https://stackoverflow.com/a/67335037/712005). So I manually changed the webpack config in my app to polyfill for crypto by doing:
yarn add crypto-browserify
And adding in gatsby-node.js:
Unfortunately this does not solve the issue. I still get:
when building the app.
I even tried:
But that does not work either.
Could it be that
prevents polyfilling for crypto?
Or is it simply that the
node:crypto
instead ofcrypto
way of importing is not recognized by webpack?If so that should be an issue for md5-hex as it says on the readme:
Works in the browser too, when used with a bundler like Webpack, Rollup, Browserify.
But probably I am just missing something obvious.
The text was updated successfully, but these errors were encountered: