【问题标题】:AWS Amplify React App Deploy Error- Too many redirect or AWS Build SettingsAWS Amplify React App Deploy 错误 - 重定向或 AWS 构建设置过多
【发布时间】:2020-08-24 16:08:56
【问题描述】:

第一次在连接到 Github 存储库的 AWS Amplify 上部署 React 应用程序。应用程序在本地工作,并且似乎在 AWS 上成功构建。当我在 Chrome 中启动应用程序时,我收到一个错误页面:ERR_TOO_MANY_REDIRECTS。我看到的唯一潜在问题是在 AWS 构建期间,当我开始构建设置时,我收到两个警告

version: 0.1
frontend:
  phases:
    # IMPORTANT - Please verify your build commands
    build:
      commands: []
  artifacts:
    # IMPORTANT - Please verify your build output directory
    baseDirectory: /
    files:
      - '**/*'
  cache:
    paths: []

我找不到太多关于纠正这些问题的指导,或者这些是否是问题所在。我在我的应用程序中使用 npm。不确定应用程序中的哪些代码对发布有用,我将提供 repo 链接。任何帮助或正确的调试方向都会很棒。 https://github.com/travelerr/chatterfield

来自 AWS 的前端构建输出:

2020-05-11T11:36:03.308Z [WARNING]: npm
2020-05-11T11:36:03.310Z [WARNING]: ERR! code ELIFECYCLE
                                    npm ERR! errno 1
                                    npm ERR! client@0.1.0 build: `react-scripts build`
                                    npm ERR! Exit status 1
                                    npm ERR!
                                    npm ERR! Failed at the client@0.1.0 build script.
                                    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-11T11:36:03.318Z [WARNING]: 
2020-05-11T11:36:03.319Z [WARNING]: npm ERR! A complete log of this run can be found in:
                                    npm ERR!     /root/.npm/_logs/2020-05-11T11_36_03_312Z-debug.log
2020-05-11T11:36:03.319Z [HELP]: Outputting the npm debug log
                                 0 info it worked if it ends with ok
                                 1 verbose cli [ '/root/.nvm/versions/node/v10.16.0/bin/node',
                                 1 verbose cli   '/root/.nvm/versions/node/v10.16.0/bin/npm',
                                 1 verbose cli   'run',
                                 1 verbose cli   'build' ]
                                 2 info using npm@6.9.0
                                 3 info using node@v10.16.0
                                 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
                                 5 info lifecycle client@0.1.0~prebuild: client@0.1.0
                                 6 info lifecycle client@0.1.0~build: client@0.1.0
                                 7 verbose lifecycle client@0.1.0~build: unsafe-perm in lifecycle true
                                 8 verbose lifecycle client@0.1.0~build: PATH: /root/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/codebuild/output/src742497908/src/chatterfield/client/node_modules/.bin:/usr/local/rvm/gems/ruby-2.4.6/bin:/usr/local/rvm/gems/ruby-2.4.6@global/bin:/usr/local/rvm/rubies/ruby-2.4.6/bin:/usr/local/rvm/bin:/root/.yarn/bin:/root/.config/yarn/global/node_modules/.bin:/root/.nvm/versions/node/v10.16.0/bin:/root/.local/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
                                 9 verbose lifecycle client@0.1.0~build: CWD: /codebuild/output/src742497908/src/chatterfield/client
                                 10 silly lifecycle client@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
                                 11 silly lifecycle client@0.1.0~build: Returned: code: 1  signal: null
                                 12 info lifecycle client@0.1.0~build: Failed to exec build script
                                 13 verbose stack Error: client@0.1.0 build: `react-scripts build`
                                 13 verbose stack Exit status 1
                                 13 verbose stack     at EventEmitter.<anonymous> (/root/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
                                 13 verbose stack     at EventEmitter.emit (events.js:198:13)
                                 13 verbose stack     at ChildProcess.<anonymous> (/root/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
                                 13 verbose stack     at ChildProcess.emit (events.js:198:13)
                                 13 verbose stack     at maybeClose (internal/child_process.js:982:16)
                                 13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
                                 14 verbose pkgid client@0.1.0
                                 15 verbose cwd /codebuild/output/src742497908/src/chatterfield/client
                                 16 verbose Linux 4.14.173-106.229.amzn1.x86_64
                                 17 verbose argv "/root/.nvm/versions/node/v10.16.0/bin/node" "/root/.nvm/versions/node/v10.16.0/bin/npm" "run" "build"
                                 18 verbose node v10.16.0
                                 19 verbose npm  v6.9.0
                                 20 error code ELIFECYCLE
                                 21 error errno 1
                                 22 error client@0.1.0 build: `react-scripts build`
                                 22 error Exit status 1
                                 23 error Failed at the client@0.1.0 build script.
                                 23 error This is probably not a problem with npm. There is likely additional logging output above.
                                 24 verbose exit [ 1, true ]

【问题讨论】:

    标签: reactjs amazon-web-services debugging deployment aws-amplify


    【解决方案1】:

    当我意识到这些构建设置并没有起到多大作用时,我遇到了同样的问题。您需要配置 React 应用程序的正确目录,安装所需的 npm 包并构建您的应用程序。最后,您需要将构建目录的完整路径配置为“baseDirectory”。

    在您的情况下,我认为正确的构建设置是:

    version: 0.1
    frontend:
      phases:
        preBuild:
          commands:
            - cd client
            - npm install
        build:
          commands: 
            - npm run build
      artifacts:
        baseDirectory: /client/build
        files:
          - '**/*'
      cache:
        paths: []
    

    一个可能对您有所帮助的有用链接:Configuring Build Settings

    【讨论】:

    • 我能够使用新的 create-react-app 重新创建错误。你是对的,这与我的文件结构有关。我目前的 React 应用程序结构为 app_name > client > project files。您提供的命令似乎正确,但我仍然收到错误消息。
    • @Justin,构建过程是否按预期工作?您可以在 Amplify Console 中当前分支的构建步骤的输出中进行调查。 “前端”选项卡下的输出应显示 npm 脚本已构建资源。至少我是这样解决问题的。
    • @Alexander no build 不再使用上述命令,尽管它们对我来说似乎是正确的。如果我不输入任何命令,构建确实有效,然后我收到 ERR_TOO_MANY_REDIRECTS。我在帖子中添加了 AWS 前端构建输出。预构建命令似乎可以工作,我相信错误在构建命令中
    猜你喜欢
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 2022-10-18
    • 2020-10-22
    • 2021-08-24
    • 2021-07-26
    • 2020-05-08
    • 2020-05-10
    相关资源
    最近更新 更多