'How to deploy Next.js in Amplify?

I don't know why this happens.

2021-09-18T00:04:20 [INFO]: Beginning deployment for application dhq4kye8grbzc, branch:main, buildId 0000000028

2021-09-18T00:04:20 [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 )

2021-09-18T00:04:20 [ERROR]: {"code":"7","message":"No ssrResources.json file"}

enter image description here



Solution 1:[1]

So, I fixed it by myself I was facing the same issue. The main problem is you are setting Next version: 11 which is not possible. As of today, we can either use 9,10 or the latest. So latest basically means version 11.

The configuration can be updated in Build Setting in your Amplify Console Platform Dashboard.

Solution 2:[2]

The problem might be in your amplify service role. I found that going into the general setting and attaching a new role with a AdministratorAccess-Amplify managed policy fixed the problem when I ran into it. https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#ssr-IAM-permissions

Solution 3:[3]

You are trying to deploy Next.js app in SSG mode while your Amplify application framework is set to SSR. To change it make sure that while you are connecting a new branch, on Frontend environments tab, build command in package.json looks like "next build && next export".

  ...
  "scripts": {
    ...
    "build": "next build && next export",
    ...
  }
  ...

Base on package.json Amplify detects framework.

https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#deploy-nextjs-ap

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abdullah Mujahid
Solution 2 Daniel Khlopotin
Solution 3