September 29, 2022 / Reading time: 2 minutes
[Solution] AWS Amplify: Cannot find file './aws-exports'
If you are using AWS Amplify and you are getting an error like this:
Unable to resolve "./aws-exports" from "App.js" # or Cannot find file './aws-exports'.
All you need to do is use
@aws-amplify/cli to pull that file from the cloud, like this:
amplify env pull --restore
Make sure you have:
@aws-amplify/cliinstalled and configured
- AWS credentials are set up
- You're using the right set of AWS credentials and you're targeting correct region (where the Amplify project is deployed)
- You're importing the
aws-exportsfile with the right path (e.g.
Alternatively, you can use
amplify push but it will also push your local changes to the cloud.
This is a common error when you are using AWS Amplify and you are trying to run your app locally on a new machine. It's a bit misleading because it's not really a problem with the file itself, but rather with the fact that you might be importing a config file that's missing.
Because it is not advised to push this file to the repository (it contains sensitive variables so by default it's listed inside
.gitignore), you need to pull it from the cloud. You can do it with
amplify env pull --restore command.
What is aws-exports.js file?
src directory that the developer specified during the
amplify init process.