Deploy failure: aws-exports not configured properly

I am trying to deploy my React.js app to Amplify with my Github connected. During the Build step, I am receiving an error due to aws-exports not being included in my .gitignore.

2020-01-07T19:35:22.127Z [INFO]: Failed to compile.
2020-01-07T19:35:22.129Z [INFO]: ./src/index.js
                                 Cannot find file './aws-exports' in './src'.
2020-01-07T19:35:22.149Z [WARNING]: error Command failed with exit code 1.
2020-01-07T19:35:22.150Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2020-01-07T19:35:22.155Z [ERROR]: !!! Build failed
2020-01-07T19:35:22.239Z [ERROR]: !!! Non-Zero Exit Code detected
2020-01-07T19:35:22.239Z [INFO]: # Starting environment caching...

What is the solution to this problem without committing aws-exports?

To solve this issue without committing aws-exports, you can add the file to your .gitignore and then manually include it during the build process.

First, make sure aws-exports.js is added to your .gitignore file.

# .gitignore
aws-exports.js

Next, you need to manually include aws-exports.js during the build process.

  1. Open your package.json file.
  2. Locate the build script.
  3. Add the following command before the build script:
"prebuild": "cp src/aws-exports.js build/aws-exports.js",

Your package.json file should now look something like this:

{
  "name": "your-app",
  "version": "0.1.0",
  "scripts": {
    "prebuild": "cp src/aws-exports.js build/aws-exports.js",
    "build": "react-scripts build",
    ...
  },
  ...
}

Save the changes to the package.json file.

Now, when you run the build command, the aws-exports.js file will be copied to the build folder, and your React app should deploy successfully to Amplify.