question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't resolve 'crypto' - updating webpack to v.5

See original GitHub issue

Hello,

To people like me that updated a project to webpack 5 and dropbox 9 and got this error:

ERROR in ./node_modules/dropbox/dist/Dropbox-sdk.min.js 1:30619-30636
Module not found: Error: Can't resolve 'crypto' in '/.../node_modules/dropbox/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
	- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "crypto": false }

The solution I’ve found was:

install node-polyfill-webpack-plugin

and on webpack config:

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin()
	]
}

Hope this will help, I’ve lost a lot of time to figuring out it…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
lorismithgeniescommented, May 18, 2021

Thank you! So helpful. My site was a Laravel Vue site so it was slightly different. I installed the node-polyfill-webpack-plugin like you suggested.

npm install node-polyfill-webpack-plugin

And, I had to add the following code to webpack.mix.js

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
mix.webpackConfig(webpack => {
    return {
        plugins: [
            new NodePolyfillPlugin()
        ]
    };
});

0reactions
ydeeracommented, Oct 20, 2022

Thank you sooooo much! I spent whole afternoon to fix it:) Two tips: 1.If you build your project using creat-react-app, the webpack.config.js is in node_modules/react-scripts/config 2.Be careful,new NodePolyfillPlugin()should be set in plugins not resolve.plugins. I made this mistake at first time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 Errors - Cannot Resolve 'crypto', 'http', and 'https' in ...
Instead of using Webpack 5, an alternative solution I have found is to downgrade to webpack@4.46.0 and react-scripts@4.0.3 .
Read more >
Module not found: Error: Can't resolve 'crypto' [Solved]
The error "Module not found: Error: Can't resolve 'crypto'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >
To v5 from v4 - webpack
Upgrade webpack 4 and its plugins/loaders · Make sure your build has no errors or warnings · Make sure to use mode ·...
Read more >
Can't resolve 'crypto' - updating webpack to v.5 - Bountysource
Can't resolve 'crypto' - updating webpack to v.5. ... To people like me that updated a project to webpack 5 and dropbox 9...
Read more >
angular breaking change: webpack < 5 used to include ...
webpack 5 angular polyfill for node.js crypto-js ... If you are in vue and your error starts like this 'Module not found: Error:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found