AWS Amplify React App Deploy Error- Too many redirect or AWS Build Settings

Viewed 3321

First time deploying a React application on AWS Amplify connected to Github repo. App works locally and seems to build successfully on AWS. When I launch app in Chrome I receive an error page: ERR_TOO_MANY_REDIRECTS. The only potential issue I see is during the AWS build is when I get to build setting I get two warnings

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: []

I cannot find much guidance on correcting these, or if these are even the problem. Im using npm for my application. Not sure what code from app would be useful to post, I will provide repo link. Any help or a point in the right direction to debug this would be great. https://github.com/travelerr/chatterfield

Frontend Build Output from 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 ]
1 Answers

I had the same issue, when I realized that these build settings are not doing much. You need to configure the proper directory of the React app, install the needed npm packages and build your application. In the end, you need to configure the full path to your build directory as 'baseDirectory'.

In your case, I think the proper build settings would be:

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

A useful link that might help you: Configuring Build Settings

Related