3

I have been struggling with deploy a next js application to azure app service as we want to render the application both static and dynamic so we need the node server to run. Is any body there is help me.

Note: I have already watched these videos and also applied these methods like adding the web.config and server.js files to root of my website but no luck it does not work. Also this article

https://parveensingh.com/next-js-deployment-on-azure-app-service/

but no luck.

enter image description here

Gangula
  • 5,193
  • 4
  • 30
  • 59
Fahad Hameed
  • 31
  • 1
  • 5
  • Take a look at this and see if this helps -https://stackoverflow.com/questions/54908662/unable-to-deploy-next-js-to-azure – Monika Reddy Nov 12 '20 at 17:09

2 Answers2

1

A more detailed answer including steps using source control you can refer to.

I also test deploying directly from VS Code, which works fine, too.

Just like the link Monika post, the step to modify package.json you might forget. And make sure your project works well locally before publish to Azure.

package.json:

"scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "node server.js"
Doris Lv
  • 3,083
  • 1
  • 5
  • 14
1

Below mentioned way's do not need server.js file or next export or pm2 scripts for deployment process.

Keep your package.json scripts as default next scripts:

"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
}

Way 1: VS Code - Azure Extension

  • Add below environment variable in your Azure App Service from Settings > Configurations

SCM_DO_BUILD_DURING_DEPLOYMENT="true"

  • Right Click on Azure App Service item and select Deploy to Web App option.
  • Select root folder for deployment.

enter image description here

Way 2: CI/CD Pipeline through Azure Devops(https://dev.azure.com/)

Here is a sample post you can refer

All credits goes to Suhas Talekar

https://itbusinesshub.com/blog/nextjs-node-app-on-azure-app-service/#how-to-host-next.js-app-on-azure's-app-service

  • Only change is you don't need pm2 script as startup command and no need to create ecosystem.config.js file as well.
  • Rest process is same.
  • Starting nextjs app is taken care by Azure.
Sandip Jadhav
  • 137
  • 1
  • 7