Node.js: 本机加密模块无法用于获取安全随机数

Node.js: Native crypto module could not be used to get secure random number

我正在使用 serverless"amazon-cognito-identity-js": "^4.5.3" 进行身份验证,偶然发现错误:Error: Native crypto module could not be used to get secure random number. 使用 CognitoUser.authenticateUser.

有几个 git 问题用多个解决方案打开,说问题已在版本 3.2.0 中修复,但它仍然在最新版本中发生。

我发现有效的解决方案是安装 amazon-cognito-identity-js@unstable

还有一个提到的解决方案,就是在文件的开头(第 1 行)添加 global.crypto = require('crypto'),但它对我不起作用。

我将离开 git 问题 link 以获得更多解决方案(如果该问题不知何故不起作用)以及更多上下文。

https://github.com/aws-amplify/amplify-js/issues/7098

我在 nodejs 中使用 amazon cognito 时遇到了这个问题。 经过如此多的尝试和尝试,我找到了解决方案,只需将 amazon-cognito-identity-js 版本更改为:

"amazon-cognito-identity-js": "^4.5.4-unstable.6"

现在它对我有用,希望它能节省您的时间,并能为所有面临此问题的人所用。 打起来,你觉得这个值得。