如何解决新的AuthError-错误:未正确配置Amplify
运行我的角度应用程序T时出现以下错误:
错误:放大功能配置不正确。
此错误通常是由以下情况之一引起的:
- 确保在应用程序的入口点将awsconfig对象传递给Amplify.configure() 有关更多信息,请参见https://aws-amplify.github.io/docs/js/authentication#configure-your-app
- 您的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"
}
}
解决方法
您的代码中似乎缺少Auth.configure(params)
。
传递与Amplify.configure(params)
相同的参数
我遇到了同样的情况。在我的应用程序中,我仅使用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
的作者 ,就我而言,我找到了一个我从未在任何地方见过的解决方案,我猜与我的代码编辑器 (Webstorm) 更相关。
上下文:
我按照 Amplify 中的建议将 aws-export.js 重命名为 .ts:
根据您的 TypeScript 版本,您可能需要在导入之前将 aws-exports.js 重命名为 aws-exports.ts,或者在您的 tsconfig 中启用 allowJs 编译器选项。
当我遇到著名的错误时,我注意到我的 aws-export.ts 没有任何 Auth 属性,并且“包含”另一个文件:
.js 版本的所有内容都得到了很好的更新,因此我将其内容复制到了我的 .ts 版本中,并且它正在运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。