【问题标题】:Module not found: Can't resolve '@aws-amplify/core'未找到模块:无法解析“@aws-amplify/core”
【发布时间】:2021-08-18 11:52:37
【问题描述】:

尝试使用放大身份验证创建 React App,但遇到此错误

找不到模块:无法解析“..\node_modules@aws-amplify\api\lib-esm”中的“@aws-amplify/core”

我一直在参考这两个链接:

我已经尝试了什么:

  • 删除 node_modules 并重新安装项目
  • 尝试使用 npm 显式安装 @aws-amplify/core(这会引发单独的错误)

任何帮助表示赞赏:)

【问题讨论】:

    标签: reactjs aws-amplify aws-amplify-cli


    【解决方案1】:

    完美的解决方案如上所述。经过大量研究,我发现了这一点。需要安装@aws-amplify/core。但除了在我的 react 应用程序中,我还必须安装更多包才能使 cognito 正常工作。

    npm i @aws-amplify/core --save --legacy-peer-deps
    npm i @aws-amplify/storage --save --legacy-peer-deps
    npm i @aws-amplify/interactions --save --legacy-peer-deps
    npm i @aws-amplify/auth --save --legacy-peer-deps
    npm i @aws-amplify/api --save --legacy-peer-deps
    npm i @aws-amplify/analytics --save --legacy-peer-deps
    npm i @aws-amplify/xr --save --legacy-peer-deps
    

    【讨论】:

      【解决方案2】:

      我在使用同样依赖于 @amplify/core 的 AWS Datastore 时遇到了这个问题。以下是我的解决方法:

      npm i @aws-amplify/core --save --legacy-peer-deps
      

      反应组件:

      import Amplify from "@aws-amplify/core
      

      在我的情况下,需要使用旧版 peer deps 标志,因为安装 React 版本高于放大/核心所需的版本。如果您还没有这样做,您可能还需要先amplify initamplify pull

      【讨论】:

        猜你喜欢
        • 2022-06-16
        • 2020-03-08
        • 2021-06-20
        • 2022-10-21
        • 1970-01-01
        • 2022-12-12
        • 2019-02-02
        • 2020-03-18
        • 2021-10-12
        相关资源
        最近更新 更多