Module not found: Error: Can't resolve 'crypto' with Webpack
See original GitHub issueDescribe the bug
This bug appears when trying to build an app using @aws-amplify/auth
with Webpack 5 because Webpack 5 does not include node.js core modules by default anymore.
To Reproduce Steps to reproduce the behavior:
- Create a React project with Webpack 5
- Install
@aws-amplify/auth
v3.4.11 - Start a build
- See error
Expected behavior The polyffil should be included 🤔
Screenshots
WARNING in ./node_modules/amazon-cognito-identity-js/es/utils/cryptoSecureRandomInt.js 47:13-30
Module not found: Error: Can't resolve 'crypto' in '/path/to/my/project/node_modules/amazon-cognito-identity-js/es/utils'
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 }
@ ./node_modules/amazon-cognito-identity-js/es/utils/WordArray.js 4:0-60 46:17-38
@ ./node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js 29:0-42 32:25-34
@ ./node_modules/amazon-cognito-identity-js/es/index.js 18:0-73 18:0-73
@ ./node_modules/@aws-amplify/auth/lib-esm/index.js 15:0-99 21:0-122 21:0-122 21:0-122
Additional context See https://webpack.js.org/migrate/5/
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Module not found: Error: Can't resolve 'crypto' - Stack Overflow
I ran into a similar issue lately while trying to use another library (tiff.js) in a small project I was experimenting with.
Read more >Can't resolve 'crypto' - updating webpack to v.5 · Issue #614
Hello, To people like me that updated a project to webpack 5 and dropbox 9 and got this error: ERROR in .
Read more >Module not found: Error: Can't resolve 'crypto' in '/Users/user ...
Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
Read more >JavaScript : Module not found: Error: Can't resolve 'crypto'
JavaScript : Module not found : Error : Can't resolve ' crypto ' [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ......
Read more >Can't resolve 'crypto' in node_modules/bson/dist react
I basically did what the error message suggest, it doesn't specify the file that you have to modify but looking around I've figured...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@harrysolovay Maybe this is an issue caused by a change to webpack 5, but the fact remains that @aws-amplify/auth doesn’t work without some polyfills… or does it? At a minimum that needs clarification.
The question is: is @aws-amplify/auth supported in browser use cases? And if so, how should it be packaged?
This appears to be a Webpack issue. I’d recommend that you file an issue in the Webpack repo.
Resolving, as this is unrelated to AmplifyJS.