amplify-js: Error: Native crypto module could not be used to get secure random number.
Describe the bug
I’m using the serverless.com framework together with: "amazon-cognito-identity-js": "^4.5.2" and I still get the error: Error: Native crypto module could not be used to get secure random number. even though it was supposed to be fixed in version 3.2.0.
It happens when I use the CognitoUser.authenticateUser method. Any updates on this issue?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 18
- Comments: 64 (25 by maintainers)
I am still experiencing this error with Angular 11 when running
ng-serve, and @aws-amplify/auth.I have tried installing
"amazon-cognito-identity-js": "^4.5.4-unstable.6",and installing latest ampliy/core, auth and pubsub. Nothing works.
I can’t use require, TS compiler is freaking out.
Thanks again for the reproduction sample @Ladvace! I have made a small adjustment in this PR that should fix the behavior you’re seeing. It is available to use now with the
unstabletag, and we will likely have a release tolatestnext week.Can you verify that
unstableworks for you?Also, with that fix, it is no longer required to add
global.crypto = require('crypto')in your code, as this will handle that automatically.@mjpaton I fixed/hacked it by doing the following: Adding to
polyfill.tsAdding the following packages to my package.json:
and added to tsconfig:
I am still getting warnings:
but Auth seems to be working. What is the proper solution for Angular 11?
+1 for mattiLeBlanc - starting a new vanilla Angular 11 project, installing Amplify and Auth
Same issue was coming to me, it was not getting reproduced on my local dev machine, was coming only on my deployed containers. I also upgraded my amazon-cognito-identity-js to 4.5.3. but no luck but finally added global.crypto = require(‘crypto’) in my code resolved the issue. Thanks.
Ok will do. Thanks for the follow up! I will update the issue once it is released to
latest.For anyone seeing the same issue using Node, you can get around it by using
amazon-cognito-identity-js@unstableand/oraws-amplify@unstableand settingglobal.crypto = require('crypto')at the top of the file before any imports.@amhinson Thanks so much Great Help !! I figured out where to add global.crypto = require(‘crypto’) . We have to added this to top of the very first test file in the test folder .
No, you shouldn’t have to add
crypto, as it is included with Node by default now.global.crypto = require('crypto')above all of therequireon line 1?3.3.7) of Amplify?