AWS Amplify build process not detecting backend environment

My AWS Amplify application has been working perfectly for months, but now I’m facing a strange issue during the build process. The app uses authentication as its only backend service.

When I try to build now, I keep getting this error:

Module not found: Error: Can't resolve '@/aws-exports' in '/codebuild/output/src987654321/src/my-app/src'

Looking at the build logs, I notice that the backend detection is failing:

## Starting Backend Build
## Checking for associated backend environment...
## No backend environment association found, continuing...

This is weird because previous builds always found the backend successfully.

I already tried these steps:

  1. Double checked that CI/CD is enabled for full-stack deployments and the backend environment settings are correct
  2. Executed amplify pull --appId <my-app-id> --envName <backend-env> command which returned that everything is current with no changes needed
  3. Verified that my app has an IAM role with “AdministratorAccess-Amplify” policy attached

I also noticed a You are in 'detached HEAD' state. message in the logs, but I tested that specific commit locally and it works fine.

The last update I made was just a simple bug fix, nothing that should affect the backend connection.

How can I debug this issue and get my backend detection working again?

sounds like a backend linkage issue. check if your app ID in the amplify folder matches what’s in the console - they sometimes get out of sync. try deleting your local amplify cache folder and run amplify push again to refresh everything.

ugh, thats super frustating! did you happen to change any branches or settings? that detached HEAD msg is kinda odd. can you check if your backend env is listed in the ampliy console? hope you get it sorted soon!

I encountered a similar issue recently, and it turned out that my team-provider-info.json file had been corrupted during deployment. The detached HEAD state occurs when Amplify struggles to associate the commit with your backend environment configuration. To resolve this, first, verify if your amplify/team-provider-info.json file exists and correctly maps the environments. If everything appears to be in order, try running amplify env checkout <your-env-name> locally and pushing those changes back. This process triggers a new deployment, rebuilding the environment association and often resolving the aws-exports import errors. Essentially, the problem is a mismatch between your current Git commit state and the backend environment metadata required for builds.