By using AWS re:Post, you agree to the Terms of Use
/Amplify won't disable SSR for non-SSR branches. How to force it to switch to SSG?/

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?

1 Answers
1
Accepted Answer

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
SUPPORT ENGINEER
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions