为什么在添加 Auth 功能时 AWS-Amplify 构建失败

Why does AWS-Amplify build fails when Auth feature is added

我最近才开始使用 Amazon 的 AWS 基本计划,我正在使用 AWS-Amplify 上传 React 应用程序,我通常使用 yarn 和 create react-app。我不确定它是否与使用 npm 的 AWS 教程有冲突,但我做对了并且在构建和部署方面取得了成功。但是,当我添加 Auth 功能时,它只适用于我的本地,但构建在部署时失败。这是错误日志:

2020-06-23T17:07:34.078Z [INFO]: Git SSH Key acquired
2020-06-23T17:07:34.155Z [INFO]: # Cloning repository: git@github.com:mav1283/amplifyapp.git
2020-06-23T17:07:34.273Z [INFO]: Agent pid 131
2020-06-23T17:07:34.329Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2020-06-23T17:07:34.558Z [INFO]: Cloning into 'amplifyapp'...
2020-06-23T17:07:35.697Z [INFO]: Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
2020-06-23T17:07:38.298Z [INFO]: # Switching to commit: 2d93cd9fca8f302a1390bce33985acccf97a8263
2020-06-23T17:07:38.388Z [INFO]: Note: checking out '2d93cd9fca8f302a1390bce33985acccf97a8263'.
                                 You are in 'detached HEAD' state. You can look around, make experimental
                                 changes and commit them, and you can discard any commits you make in this
                                 state without impacting any branches by performing another checkout.
                                 If you want to create a new branch to retain commits you create, you may
                                 do so (now or later) by using -b with the checkout command again. Example:
                                 git checkout -b <new-branch-name>
                                 HEAD is now at 2d93cd9 add auth
2020-06-23T17:07:38.389Z [INFO]: # Checking for Git submodules at: /codebuild/output/src043707224/src/amplifyapp/.gitmodules
2020-06-23T17:07:38.411Z [INFO]: # Retrieving cache...
2020-06-23T17:07:40.086Z [INFO]: # Extracting cache...
2020-06-23T17:07:43.479Z [INFO]: # Extraction completed
2020-06-23T17:07:43.604Z [INFO]: # Retrieving environment cache...
2020-06-23T17:07:43.642Z [INFO]: # Retrieved environment cache
2020-06-23T17:08:17.476Z [INFO]: ## Starting Frontend Build
                                 # Starting phase: preBuild
                                 # Executing command: yarn install
2020-06-23T17:08:18.203Z [INFO]: yarn install v1.16.0
2020-06-23T17:08:18.305Z [INFO]: [1/4] Resolving packages...
2020-06-23T17:08:18.838Z [INFO]: [2/4] Fetching packages...
2020-06-23T17:08:48.710Z [INFO]: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
2020-06-23T17:08:48.712Z [INFO]: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
2020-06-23T17:08:48.719Z [INFO]: info fsevents@1.2.13: The platform "linux" is incompatible with this module.
2020-06-23T17:08:48.723Z [INFO]: info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
                                 info fsevents@2.1.3: The platform "linux" is incompatible with this module.
                                 info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
2020-06-23T17:08:48.728Z [INFO]: [3/4] Linking dependencies...
2020-06-23T17:08:48.732Z [WARNING]: warning "@aws-amplify/ui-react > @aws-amplify/ui-components@0.5.2" has unmet peer dependency "@aws-amplify/auth@^2.1.5".
                                    warning "@aws-amplify/ui-react > @aws-amplify/ui-components@0.5.2" has unmet peer dependency "@aws-amplify/core@^2.2.4".
                                    warning "@aws-amplify/ui-react > @aws-amplify/ui-components@0.5.2" has unmet peer dependency "@aws-amplify/xr@^1.1.5".
                                    warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
2020-06-23T17:08:48.734Z [WARNING]: warning "aws-amplify > @aws-amplify/api@3.1.17" has incorrect peer dependency "@aws-amplify/pubsub@^2.1.1".
                                    warning "aws-amplify > @aws-amplify/datastore@2.2.4" has unmet peer dependency "@react-native-community/netinfo@^5.5.0".
                                    warning "aws-amplify > @aws-amplify/api > @aws-amplify/api-graphql@1.1.0" has incorrect peer dependency "@aws-amplify/pubsub@^2.1.1".
2020-06-23T17:08:48.736Z [WARNING]: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
2020-06-23T17:08:56.100Z [INFO]: [4/4] Building fresh packages...
2020-06-23T17:08:57.025Z [INFO]: Done in 38.83s.
2020-06-23T17:08:57.047Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
                                 # Executing command: yarn run build
2020-06-23T17:08:57.210Z [INFO]: yarn run v1.16.0
2020-06-23T17:08:57.237Z [INFO]: $ react-scripts build
2020-06-23T17:08:58.125Z [INFO]: Creating an optimized production build...
2020-06-23T17:08:59.577Z [INFO]: Failed to compile.
2020-06-23T17:08:59.579Z [INFO]: ./src/index.js
                                 Cannot find file './aws-exports' in './src'.
2020-06-23T17:08:59.596Z [WARNING]: error Command failed with exit code 1.
2020-06-23T17:08:59.597Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2020-06-23T17:08:59.602Z [ERROR]: !!! Build failed
2020-06-23T17:08:59.677Z [ERROR]: !!! Non-Zero Exit Code detected
2020-06-23T17:08:59.677Z [INFO]: # Starting environment caching...
2020-06-23T17:08:59.678Z [INFO]: # Environment caching completed
Terminating logging...

出于安全原因,aws-exports.js 添加到 git 在放大项目中默认忽略。此文件是在您 运行 amplify push 命令时生成的。

backend:
  phases:
    # IMPORTANT - Please verify your build commands
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple

确保您的构建设置 -> amplify.yml 文件中有 amplifyPush --simple,以便在您的放大构建中生成 aws-exports

创建服务角色和更改 CLI 版本对我有用。如果你只做一个而不做另一个,你将无法解决问题。因此创建服务角色并将高级设置中的 CLi 版本更新为最新。这会像魔术一样起作用。