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.

Module not found: Error: Can't resolve 'crypto' with Webpack

See original GitHub issue

Describe 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:

  1. Create a React project with Webpack 5
  2. Install @aws-amplify/auth v3.4.11
  3. Start a build
  4. 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:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
acchoucommented, Feb 5, 2021

@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?

3reactions
harrysolovaycommented, Nov 13, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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