aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
452 stars 113 forks source link

Next.js SSG Deploy Fail with no reason #1854

Closed peterwmwong closed 3 years ago

peterwmwong commented 3 years ago

Before opening, please confirm:

App Id

d1ka0gxxs2xqs1

Region

us-west-2

Amplify Console feature

Not applicable

Describe the bug

After adjusting our package.json so the newly added Amplify Next.js SSR integration would detect our application as an SSG (not SSR). The "Deploy" stage fails... no logs indicating why.

Screen Shot 2021-05-18 at 6 12 27 PM

The "Build" phase appears to be completing successfully.

2021-05-18T23:23:03.156Z [INFO]: # Executing command: npm run build
2021-05-18T23:23:03.310Z [INFO]: > upc-tv@0.0.1 build /codebuild/output/src803710412/src/sdn-product/tools/upc-tv
                                 > next build && next export
2021-05-18T23:23:03.585Z [INFO]: info  - Loaded env from /codebuild/output/src803710412/src/sdn-product/tools/upc-tv/.env
2021-05-18T23:23:03.809Z [INFO]: info  - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
2021-05-18T23:23:03.912Z [INFO]: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2021-05-18T23:23:03.912Z [INFO]: info  - Checking validity of types...
2021-05-18T23:23:03.924Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2021-05-18T23:23:03.925Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2021-05-18T23:23:08.642Z [INFO]: info  - Creating an optimized production build...
2021-05-18T23:23:22.927Z [INFO]: info  - Compiled successfully
                                 info  - Collecting page data...
2021-05-18T23:23:23.547Z [INFO]: info  - Generating static pages (0/3)
2021-05-18T23:23:24.157Z [INFO]: info  - Generating static pages (3/3)
2021-05-18T23:23:24.157Z [INFO]: info  - Finalizing page optimization...
2021-05-18T23:23:24.162Z [INFO]: 
2021-05-18T23:23:24.179Z [INFO]: Page                                Size     First Load JS
                                 ┌ ○ /                               109 kB          195 kB
                                 ├   └ css/94cfd6257228ee105d01.css  656 B
                                 ├   /_app                           0 B            86.4 kB
                                 └ ○ /404                            3.05 kB        89.4 kB
                                 + First Load JS shared by all       86.4 kB
                                 ├ chunks/433.67dc2c.js            10.8 kB
                                 ├ chunks/778.d75648.js            6.84 kB
                                 ├ chunks/795.aaad3c.js            21.1 kB
                                 ├ chunks/commons.98f01d.js        3.14 kB
                                 ├ chunks/framework.4a6a71.js      42.4 kB
                                 ├ chunks/main.5ec178.js           157 B
                                 ├ chunks/pages/_app.5272ad.js     921 B
                                 └ chunks/webpack.44a62b.js        993 B
2021-05-18T23:23:24.179Z [INFO]: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
                                 ○  (Static)  automatically rendered as static HTML (uses no initial props)
                                 ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
                                 (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
2021-05-18T23:23:24.412Z [INFO]: info  - Loaded env from /codebuild/output/src803710412/src/sdn-product/tools/upc-tv/.env
2021-05-18T23:23:24.637Z [INFO]: info  - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
2021-05-18T23:23:24.820Z [INFO]: info  - using build directory: /codebuild/output/src803710412/src/sdn-product/tools/upc-tv/.next
2021-05-18T23:23:24.822Z [INFO]: info  - Copying "static build" directory
2021-05-18T23:23:24.824Z [INFO]: info  - No "exportPathMap" found in "next.config.js". Generating map from "./pages"
2021-05-18T23:23:24.825Z [INFO]: info  - Launching 3 workers
2021-05-18T23:23:24.825Z [INFO]: info  - Exporting (0/2)
2021-05-18T23:23:24.825Z [INFO]: info  - Copying "public" directory
2021-05-18T23:23:25.033Z [INFO]: info  - Exporting (2/2)
2021-05-18T23:23:25.033Z [INFO]: Export successful. Files written to /codebuild/output/src803710412/src/sdn-product/tools/upc-tv/out
2021-05-18T23:23:25.044Z [INFO]: # Executing command: npm run export
2021-05-18T23:23:25.195Z [INFO]: > upc-tv@0.0.1 export /codebuild/output/src803710412/src/sdn-product/tools/upc-tv
                                 > echo 'Temporarily disabled: https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#deploy-nextjs-app'
2021-05-18T23:23:25.199Z [INFO]: Temporarily disabled: https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#deploy-nextjs-app
2021-05-18T23:23:25.203Z [INFO]: # Completed phase: build
2021-05-18T23:23:25.203Z [INFO]: ## Build completed successfully
2021-05-18T23:23:25.204Z [INFO]: # Starting caching...
2021-05-18T23:23:25.259Z [INFO]: Creating cache artifact...
2021-05-18T23:23:25.265Z [INFO]: # Cache artifact is: 0MB
2021-05-18T23:23:25.265Z [INFO]: # Uploading cache artifact...
2021-05-18T23:23:25.368Z [INFO]: # Caching completed
2021-05-18T23:23:25.373Z [INFO]: No custom headers found.
2021-05-18T23:23:25.420Z [INFO]: # Starting build artifact upload process...
2021-05-18T23:23:25.506Z [INFO]: # Build artifact is: 0MB
2021-05-18T23:23:25.506Z [INFO]: # Uploading build artifact '__artifacts.zip'...
2021-05-18T23:23:25.512Z [INFO]: # Build artifact is: 0MB
2021-05-18T23:23:25.512Z [INFO]: # Uploading build artifact '__artifactsHash.zip'...
2021-05-18T23:23:25.692Z [INFO]: # Build artifact upload completed
2021-05-18T23:23:25.692Z [INFO]: # Starting environment caching...
2021-05-18T23:23:25.692Z [INFO]: # Uploading environment cache artifact...
2021-05-18T23:23:25.905Z [INFO]: # Environment caching completed

Oddly enough this same application/repository (git mirror) works fine on another AWS account...

Expected behavior

A successful deploy.

Reproduction steps

  1. Push a commit to branch Amplify App is watching

Build Settings

version: 1
        applications:
          - frontend:
              phases:
                preBuild:
                  commands:
                    - nvm install
                    - nvm use
                    - npm ci
                build:
                  commands:
                    - ./build-env-vars.sh ${AmplifySecretsVersion} ${RootStackName}
                    - npm run build
                    - npm run export
              artifacts:
                baseDirectory: out
                files:
                  - '**/*'
              cache:
                paths:
                  - node_modules/**/*
            appRoot: tools/upc-tv

Additional information

No response

Athena96 commented 3 years ago

hi @peterwmwong the issue is because from the build history it looks like the app started off being detected as an SSR app, but then was switched back to SSG and the service role was removed

and since the service role was removed our build didn't have permission to change the framework back to SSG (causing the issue you see in the Deploy step). I manually update your framework to SSG, so please try another build and let us know if you continue to experience the issue. Thanks!

peterwmwong commented 3 years ago

@Athena96 Thanks for taking a look. Unfortunately, I just tried (pushed a whitespace commit, no config changes) and got the same results. This latest build/deploy is Build 10.

peterwmwong commented 3 years ago

@Athena96 Is there a settings page/AWS CLI command/log that indicates what mode (SSG vs SSR) an Amplify App is detected as?

jericopulvera commented 3 years ago

@Athena96 can you please re-open this issue #1847

This might be related. I'm afraid you're not receiving an alert since the issue is closed.

Athena96 commented 3 years ago

@peterwmwong you can see the framework we detected for your app in the General App Settings page for your app. @jericopulvera I will re-open the #1847

peterwmwong commented 3 years ago

@Athena96

  1. For the knowing the framework, I checked my App Settings. Not sure the absence of a value is a bug, or simply saying "no framework detected"
Screen Shot 2021-05-19 at 10 54 05 AM
  1. Not sure you saw my earlier comment about retrying a build/deploy and it still failed.
ACPK commented 3 years ago

@peterwmwong - Have you resolved the issue yet? We're also have the exact same problem. This problem started a week ago for us.

@Athena96 - Could you update our app (diqowywkubjcd) to SSG too? How can we do this on our own as deploys broke last week for us?

peterwmwong commented 3 years ago

@ACPK - Doing some experiments on another account, I think a workaround is to just recreate the Amplify App with the documented package.json incantations so Amplify detects it's SSG and not SSR for the first build/deploy.

Which depending on how your situation might be easy or hard. For us, we're using CloudFormation to create the Amplify App, so we...

  1. Commented out the Amplify App resources from the CloudFormation template.yaml
  2. Deploy CloudFormation (verify Amplify App is removed in the Amplify Console)
  3. Update the package.json (one npm script with next build && next export, instead of next build/next export as separate npm scripts)
  4. Uncomment out the Amplify App resources from the CloudFormation template.yaml
  5. Deploy CloudFormation (verify Amplify App is created in the Amplify Console)
  6. Trigger a build (In our case, push a commit to the git branch being watched by the Amplify App)
  7. Verify a successful build/deploy (build log should not contain "Starting SSR Build..." and deploy actually... deploys)

@Athena96 - If I don't hear back tomorrow, I'll just go forward with the above workaround and hope it works in this account. Would still be interested in answers to be previous question. Thanks.

grnwld commented 3 years ago

Encountering same issue. I removed next as a dependency in package.json, as it's only used in a separate portion of the site, and build script is set to node scripts/build.js. Amplify still errors out at Starting SSR build...

Amplify and Beanstalk have been rather finnicky lately. I wouldn't expect to have to tweak builds and deployments that previously worked fine.

AppID: d14iornxvomy5k Region: us-east-1

nestorochoa commented 3 years ago

Same Issue here and the solution might be just switching the App to SSG again, so how we can change that one manually? AppID: d3td4in2dnk19a Region: ap-southeast-2

ncoop720 commented 3 years ago

I had the same issue and resolved it by adding administrator access to the service role.

Athena96 commented 3 years ago

Here are the steps for converting an existing SSR app to SSG: https://github.com/aws-amplify/amplify-console/blob/master/FAQ.md#convert-an-ssr-app-to-ssg

Closing this issue, please feel free to re-open if you are still facing the issue

r-moore commented 3 years ago

@Athena96 what do you do if you are not even using Next.js and your Amplify deploys have started failing? I've never used SSR in this create-react-app project.

Screenshot 2021-09-03 at 12 49 40 image

Auto-detecting whether the app is SSR feels wrong to me, surely it should be an explicit config option (or setting in console)?

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.