11

I'm on the third module of this AWS tutorial to build a React app with AWS, Amplify and GraphQL but the build keeps breaking. When I ran amplify push --y the CLI generated ./src/aws-exports.js and added the same file to the .gitignore. So I'm not surprised the build is failing, since that file isn't included when I push my changes.

So I'm not sure what to do here. Considering it's automatically added to the .gitignore I'm hesitant to remove it.

Any suggestions?

Duderino9000
  • 2,535
  • 4
  • 31
  • 37

4 Answers4

5

I'm assuming you are trying to build your app in a CI/CD environment? If that's the case then you need to build the backend part of your amplify app before you can build the frontend component.

For example, my app is building from the AWS amplify console and in my build settings I have

version: 0.1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - yarn install --frozen-lockfile
    build:
      commands:
        - yarn build
  artifacts:
    baseDirectory: build
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

Note that the backend is building first with the amplifyPush --simple command. This is what generates the aws-exports.js file.

Matthew
  • 61
  • 1
  • 1
    In my case `amplifyPush --simple` worked well. But it would be better if it could skip actual push operation. It looks like wasting. – Kim-Jimin May 20 '21 at 07:43
3

The 'aws-exports.js' file gets created automatically when AWS Amplify runs the CI/CD deployment build process and gets configured with the appropriate settings for the environment you are deploying to.

And for this reason it is included in the .gitignore. You don't want your local test configuration to be used in your production deployment for example.

As per Matthe's answer above the should be generated when the build script runs the 'amplifyPush' command. For some reason this is not working for me at the moment though!

Duncan Groenewald
  • 8,496
  • 6
  • 41
  • 76
2

AWS added support to automatically generate the aws-exports.js at build time to avoid getting the error: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-config-autogeneration.html

Nikhil
  • 743
  • 7
  • 14
0

You generate your aws-exports file when you run a successful amplify push command.

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

You can also check out build settings on documentation.