【问题标题】:Node.js: Native crypto module could not be used to get secure random numberNode.js:本机加密模块无法用于获取安全随机数
【发布时间】:2020-11-12 13:33:14
【问题描述】:

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

有多个解决方案打开了几个 git 问题,表示该问题已在版本 3.2.0 中修复,但在最新版本中仍然存在。

【问题讨论】:

    标签: node.js amazon-cognito serverless-framework


    【解决方案1】:

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

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

    如果这个问题不起作用,我将离开 git 问题链接以获取更多解决方案,以及更多上下文。

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

    【讨论】:

    • 不适合我;我在我的package.json 中尝试了global.cryptoamazon-cognito-identity-js 的不同排列方式的各种版本。该软件包是否应该安装在其他地方?
    【解决方案2】:

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

    “amazon-cognito-identity-js”:“^4.5.4-unstable.6”

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

    【讨论】:

    • 不需要重复答案
    • @CataHotea 这不是重复的,而是确切的解决方案,我认为对于第一次遇到这个问题的人来说更清楚。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    相关资源
    最近更新 更多