skip to Main Content

Is it possible to deploy NextJs SSR to Azure Static Web Apps?

In Microsoft doc they said

In the Build Details section, select Custom from the Build Presets.

https://learn.microsoft.com/en-us/azure/static-web-apps/deploy-nextjs

But I see in Build Presets there is NextJs
Build Presets Image

Is it new feature that supports all NextJs functionalities including SSR ?

In Azure/static-web-apps repo I found one comment from 8 March 2022 that says:

As of today, Static Web Apps only supports static rendering of Next.js Apps. However, the team is currently working on supporting framework-specific Server-side rendering for Next.js and you should be seeing a public preview of the same soon.

https://github.com/Azure/static-web-apps/issues/749#issuecomment-1061993049

I created Azure Static Web App with NextJs preset with output_location: ".next"
because when run "npm run build" the output folder is ".next"

but GitHub hook failed with this error

Failed to find a default file in the app artifacts folder (.next). Valid default files: index.html,Index.html.
If your application contains purely static content, please verify that the variable ‘app_location’ in your workflow file points to the root of your application.
If your application requires build steps, please validate that a default file exists in the build output directory.

The only way I could deploy NextJs in Azure Static Web Apps is when I change the build command in package.json to

"build": "next build && next export",

and for output location type "out" which is SSG but not SSR.

3

Answers


  1. I was trying to do the same thing. It looks like Static Web Apps doesn’t support SSR yet but they may add support soon as you’ll see here https://github.com/Azure/static-web-apps/issues/749

    BTW, I used the same commands to deploy the static content to Azure SWA.

    Login or Signup to reply.
  2. https://github.com/Azure/static-web-apps/discussions/921

    This will be supported soon, Microsoft is working on this

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search