【问题标题】:New AuthError - Error: Amplify has not been configured correctly新的 AuthError - 错误:未正确配置 Amplify
【发布时间】:2020-09-03 18:53:14
【问题描述】:

运行我的 Angular 应用程序时出现以下错误:

错误:未正确配置 Amplify。
此错误通常由以下情况之一引起:

  1. 确保将 awsconfig 对象传递给应用程序入口点中的 Amplify.configure() 更多信息请参见https://aws-amplify.github.io/docs/js/authentication#configure-your-app
  2. 您的 node_modules 中可能存在多个相互冲突的 aws-amplify 或 amplify 软件包版本。 尝试删除您的 node_modules 文件夹并使用 yarn install 重新安装依赖项

一个奇怪的事情是,这只有在启用--prod 时才会发生。

直到今天(9 月 9 日)都还好,但我不知道是哪个软件包版本导致了问题。我已经尝试过使用 aws-amplify 和 aws-amplify-angular 中的旧版本,但它似乎是其他包。我怎么知道是哪一个?

package.json

{
  "name": "proyect",
  "version": "0.5.2",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:prod": "ng build --buildOptimizer=true --optimization=true --prod=true",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.0",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/forms": "~8.2.0",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "@ngrx/effects": "^8.6.0",
    "@ngrx/store": "^8.6.0",
    "@ngx-translate/core": "^12.1.2",
    "@ngx-translate/http-loader": "^5.0.0",
    "aws-amplify": "^3.0.7",
    "aws-amplify-angular": "^5.0.7",
    "bootstrap": "^4.5.0",
    "chart.js": "^2.9.3",
    "chartjs-plugin-datalabels": "^0.7.0",
    "moment": "^2.26.0",
    "ng2-charts": "^2.3.2",
    "ngx-mask": "^8.2.0",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.25",
    "@angular/cli": "~8.2.0",
    "@angular/compiler-cli": "~8.2.0",
    "@angular/language-service": "~8.2.0",
    "@ngrx/store-devtools": "^9.1.0",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "json-server": "^0.16.1",
    "karma": "^5.1.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "ng2-charts-schematics": "^0.1.7",
    "protractor": "^7.0.0",
    "ts-node": "8.5.0",
    "tslint": "^5.20.1",
    "typescript": "~3.5.3"
  }
}

【问题讨论】:

  • 你解决了吗?

标签: angular aws-amplify


【解决方案1】:

您的代码中似乎缺少Auth.configure(params)

传递与Amplify.configure(params) 相同的参数

【讨论】:

    【解决方案2】:

    我也遇到过同样的情况。在我的应用程序中,我只使用 Auth 组件,所以我必须添加 Auth.configure()

    import { Amplify, Auth } from 'aws-amplify';
    Amplify.configure(environment.amplify);
    // The following code-line solved the issue
    Auth.configure(environment.amplify);
    

    感谢https://github.com/aws-amplify/amplify-js/issues/5429的作者

    【讨论】:

      【解决方案3】:

      就我而言,我发现了一个我从未在任何地方看到过的解决方案,我猜它与我的代码编辑器 (Webstorm) 更相关。

      上下文:
      按照 Amplify 中的建议,我将 aws-export.js 重命名为 .ts:

      根据您的 TypeScript 版本,您可能需要在导入之前将 aws-exports.js 重命名为 aws-exports.ts,或者在您的 tsconfig 中启用 allowJs 编译器选项。

      当我遇到著名的错误时,我注意到我的 aws-export.ts 没有任何 Auth 属性,并且“包含”另一个文件:

      .js 版本对所有内容都进行了很好的更新,因此我将其内容复制到我的 .ts 版本中,并且它正在工作。

      【讨论】:

      • 这也是我的解决方案。每个人都说上面的解决方案,但我敢打赌这是正确的解决方案
      猜你喜欢
      • 2020-12-15
      • 2020-12-16
      • 2021-11-20
      • 2021-01-30
      • 1970-01-01
      • 2023-03-22
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多