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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠