Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Can't resolve './amplifyconfiguration.json' in build stage #13451

Closed
LennyRamos opened this issue Dec 5, 2023 · 24 comments
Closed

Error: Can't resolve './amplifyconfiguration.json' in build stage #13451

LennyRamos opened this issue Dec 5, 2023 · 24 comments
Labels
hosting Issues tied to hosting category pending-triage Issue is pending triage question General question

Comments

@LennyRamos
Copy link

LennyRamos commented Dec 5, 2023

Amplify CLI Version

12.8.2

Question

So I have everything wired up. Backend and Frontend.

I am running the CI/CD pipeline to build and deploy the app.

In the build stage, it gets to this error:

2023-12-05T16:18:38.760Z [INFO]: Creating an optimized production build...
2023-12-05T16:18:39.438Z [INFO]: Failed to compile.
2023-12-05T16:18:39.438Z [INFO]: Module not found: Error: Can't resolve './amplifyconfiguration.json' in '/codebuild/output/somepath/src'
2023-12-05T16:18:39.452Z [ERROR]: !!! Build failed
2023-12-05T16:18:39.453Z [ERROR]: !!! Non-Zero Exit Code detected

This makes sense given that it is pulling the project from Git Hub and that file was not committed.

What is the work around this? I have read not to commit either amplifyconfiguration.json or aws-exports.js, so i haven't

More information, building off of main branch in repo

Thanks!

@LennyRamos LennyRamos added pending-triage Issue is pending triage question General question labels Dec 5, 2023
@ykethan
Copy link
Member

ykethan commented Dec 5, 2023

Hey @LennyRamos, thank you for reaching out. This appears to be happening on you frontend build phase on AWS Amplify console.
The aws-exports or amplifyconfiguration are generated on amplify push. For information, refer to document

Does the cicd yml script have a backend build phase with

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

as this should push your backend and generate the config file.

@ykethan ykethan added hosting Issues tied to hosting category pending-response Issue is pending response from the issue author labels Dec 5, 2023
@LennyRamos
Copy link
Author

LennyRamos commented Dec 5, 2023

Ohhh that's awesome!

Would I drop that in the "amplify.yml" file that was generated for the amplify project?

All pps > App > App settings: Build settings ?

Currently, I only see the frontend in the yml. with the following:

version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: build
files:
- '/*'
cache:
paths:
- node_modules/
/*

I attached the backend env that I am using

image

but it doesnt seem like that updates the yml

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 5, 2023
@LennyRamos
Copy link
Author

One last question, I see from these docs that they have a sample yml syntax

does it matter if I place the backend build before front end?

For more clarity, in the build logs I do see the backend being built, just no yml for it,

@LennyRamos
Copy link
Author

From what you said and what's in these logs, im assuming I just need to drop those build commands in the amplify.yml?

2023-12-05T16:17:45.281Z [INFO]: ✅ Initialized your environment successfully.
2023-12-05T16:17:45.282Z [INFO]: �[32mYour project has been successfully initialized and connected to the cloud!�[39m
�[32mSome next steps:�[39m
�[0m"amplify status" will show you what you've added already and if it's locally configured or deployed�[0m
�[0m"amplify add " will allow you to add features like user login or a backend API�[0m
�[0m"amplify push" will build all your local backend resources and provision it in the cloud�[0m
�[0m"amplify console" to open the Amplify Console and view your project status�[0m
�[0m"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud�[0m
�[32mPro tip:�[39m
�[0mTry "amplify add api" to create a backend API and then "amplify push" to deploy everything�[0m
2023-12-05T16:17:45.282Z [INFO]: ⚠️ The maximum number of apps that you can create with Amplify in this region has likely been reached:
For more information on Amplify Service Quotas, see:
https://docs.aws.amazon.com/general/latest/gr/amplify.html#service-quotas-amplify
2023-12-05T16:17:46.720Z [INFO]: ## Completed Backend Build
2023-12-05T16:17:46.723Z [INFO]: ## Starting Frontend Build

@LennyRamos
Copy link
Author

I first tried changing the yml in the UI and build but that failed.

Then I downloaded the yml and placed it at root of project. I saw that when I rebuild the project with the yml in root it was executing.

same error

Here it is

2023-12-05T23:45:49.850Z [INFO]: Creating an optimized production build...
2023-12-05T23:45:50.558Z [INFO]: Failed to compile.
2023-12-05T23:45:50.558Z [INFO]: Module not found: Error: Can't resolve './amplifyconfiguration.json' in '/codebuild/output/src2491452975/src/frontend/src'
2023-12-05T23:45:50.573Z [ERROR]: !!! Build failed
2023-12-05T23:45:50.573Z [ERROR]: !!! Non-Zero Exit Code detected
2023-12-05T23:45:50.574Z [INFO]: # Starting environment caching...
2023-12-05T23:45:50.574Z [INFO]: # Environment caching completed

@LennyRamos
Copy link
Author

comparing my logs to others I also have this error at the beginning, not sure if related

2023-12-06T00:30:40.019Z [INFO]: # Checking for Git submodules at: /codebuild/output/src2466364651/src/frontend/.gitmodules
2023-12-06T00:30:40.026Z [INFO]: # Retrieving environment cache...
2023-12-06T00:30:40.065Z [WARNING]: ! Unable to write cache: {"code":"ERR_BAD_REQUEST","message":"Request failed with status code 404"})}

@charlieforward9
Copy link

Does the ./amplifyconfiguration.json only generate on amplify push, or does it also generate on amplify pull? I am having an issue with it not generating on the pull command.

@LennyRamos
Copy link
Author

@charlieforward9
Try push since it seems like only on amplify push do those files get generated

https://docs.amplify.aws/javascript/tools/cli/start/key-workflows/#amplify-push

@ykethan
Copy link
Member

ykethan commented Dec 6, 2023

Hey, running amplify pull --appId <app-id> --envName <env-name> should also generate the config files.
Curious, do you observe a similar error when building the project locally?

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 6, 2023
@LennyRamos
Copy link
Author

No, locally everything runs pretty smooth and well. I am able to launch my project and interact with it on localhost

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 6, 2023
@LennyRamos
Copy link
Author

LennyRamos commented Dec 6, 2023

Is there a message for when that file gets generated?

I see that for aws.exports.js there is a message but not for amplifyconfiguration

## Starting Backend Build
# Starting phase: build
## Running amplify pull to generate aws-exports.js file for frontend

Am I suppose to see this message in the output?
'# Execute Amplify CLI with the helper script'

@ykethan
Copy link
Member

ykethan commented Dec 6, 2023

@LennyRamos interesting the looking into the logs the backend build seems to be running as expected.

 ## Completed Backend Build

in the yml file could you try listing the files by adding ls at the backend stage after the push for src folder and the root of the project as a check to ensure the config files are getting generated.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 6, 2023
@LennyRamos
Copy link
Author

Will do and relay what I see.

For future reference, is there a way to remote into the docker containers where the app is built?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 6, 2023
@LennyRamos
Copy link
Author

amplify.yml

backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
        - ls src
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
        - ls src
    build:
      commands:
        - npm run build --verbose
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Logs of ls src

# Executing command: ls src
2023-12-06T17:48:33.433Z [INFO]: App.css
                                 App.js
                                 App.test.js
                                 assets
                                 aws-exports.js
                                 components
                                 graphql
                                 index.css
                                 index.js
                                 logo.svg
                                 pages
                                 reportWebVitals.js
                                 setupTests.js
                                 ui-components

Im pretty sure the error is that the pipeline is not executing amplifyPush --simple
but unsure why or how its able to build the backend then

the amplify.yml in build settings is also the same structure as the one in git, just without the ls src

@LennyRamos
Copy link
Author

I see these messages too

 # Retrieving cache...
2023-12-06T17:47:15.146Z [INFO]: # Extracting cache...
2023-12-06T17:47:20.237Z [INFO]: # Extraction completed
2023-12-06T17:47:20.373Z [INFO]: # Retrieved cache
2023-12-06T17:47:51.714Z [INFO]: ## Starting Backend Build
                                 # Starting phase: build

is this looking for a cache of an old amplify.yml and using that? thats the only thing i can think of

@ykethan
Copy link
Member

ykethan commented Dec 6, 2023

@LennyRamos is the Amplify CLI on the build setting set to latest? looking at the ls output it appears the build maybe using an older version. we can also confirm this by adding amplify --version in the yml. The json version of the file was added in the latest versions of Amplify CLI.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 6, 2023
@LennyRamos
Copy link
Author

LennyRamos commented Dec 6, 2023

@ykethan right on the money 🤑🤑🤑

2023-12-06T19:17:03.841Z [INFO]: # Executing command: amplify --version
2023-12-06T19:17:05.087Z [INFO]: 10.5.2

where can i update the version in the build settings?

locally i am using 12.8.2

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 6, 2023
@ykethan
Copy link
Member

ykethan commented Dec 6, 2023

@LennyRamos great, we can change to latest version by using any of the following methods.

  1. add the Amplify CLI install command to yml script before the push command, npm install -g @aws-amplify/cli.
  2. modify the build settings to change the image to use al:2023 which uses the latest cli version.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Dec 6, 2023
@LennyRamos
Copy link
Author

LennyRamos commented Dec 6, 2023

Here ?

image

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Dec 6, 2023
@ykethan
Copy link
Member

ykethan commented Dec 6, 2023

@LennyRamos actually just noticed the package override does not have any Amplify CLI.
could you add the package override for Amplify CLI as follows then rebuild.
image

@LennyRamos
Copy link
Author

image

oddly enough, just by changing the build image was enough.

For anyone who comes accross this:

  1. add backend build command (scroll up for example)
  2. check build image
  3. add package override if the first two steps fail.

@LennyRamos
Copy link
Author

@ykethan Thanks a bunch in helping me debug this!!!

@ykethan
Copy link
Member

ykethan commented Dec 6, 2023

Glad to hear you were able to get a successful build, i will be closing the issue for now. Please feel free in reaching out to us again.

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
Copy link

github-actions bot commented Dec 6, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hosting Issues tied to hosting category pending-triage Issue is pending triage question General question
Projects
None yet
Development

No branches or pull requests

3 participants