Amplify won't disable SSR for non-SSR branches. How to force it to switch to SSG?

0

In Amplify console, I connected one branch that contained experiments on adding Next.js and it seems like the whole app switched to SSR mode. Even though all the branches now are SSG (using create-react-app), it's still fails "deploy" stage with following message:

2022-03-28T10:29:07 [INFO]: Beginning deployment for application ..., branch:..., buildId ...
2022-03-28T10:29:08 [INFO]: Cannot find any generated SSR resources to deploy. If you intend for your app to be SSR, please check your app Service Role permissions. Otherwise, please check out our docs on how to setup your app to be detected as SSG (https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#deploy-nextjs-app)
2022-03-28T10:29:08 [ERROR]: {"code":"7","message":"No ssrResources.json file"}

And this happens while package.json contains following commands:

  "scripts": {
    "start": "gatsby develop",
    "serve": "gatsby serve",
    "build": "gatsby build",
  }

And amplify.yml is this:

version: 0.2
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  customHeaders:
    - pattern: '/apple-app-site-association.js'
      headers:
        - key: 'Content-Type'
          value: 'application/json'
    - pattern: '/*.xml'
      headers:
        - key: 'Content-Type'
          value: 'application/xml'

What do I do?

devtwo
已提問 2 年前檢視次數 1810 次
1 個回答
1
已接受的答案

Hello,

Thank you for reaching out to us.

Please follow below steps as mentioned in the link [1] :

  1. Please run AWS CLI commands to overwrite how Amplify detects the framework:

       aws amplify update-app --app-id <APP_ID> --platform WEB --region <REGION>
       aws amplify update-branch --app-id <APP_ID> --branch-name <BRANCH_NAME> --framework 'Next.js - SSG' --region <REGION>
    
  2. Then update build spec to point the baseDirectory to out. e.g.

        version: 1
        frontend:
              ...
              artifacts:
                    baseDirectory: out
              ...
    
  3. Update the build command in your package.json to use next export, then commit this to trigger a new non-SSR build.

  4. Finally, go to the "Rewrites and redirects" tab in the Amplify console, and delete the first rewrite rule that was re-writing to their SSR CloudFront distribution.

References:

  1. https://github.com/aws-amplify/amplify-hosting/blob/main/FAQ.md#convert-an-ssr-app-to-ssg
AWS
支援工程師
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南