Deploying next app to Azure fails because node_modules need to be re-installed

807 Views Asked by At

I'm creating a build in Azure pipelines and copying node_modules as well as 'out' folder, package.json, package-lock.json, next.config.js and .next folder. I copy all of these into an artifact directory. I then zip this as an artifact and then do a zip deploy to Azure App Service Linux Web app.

However running npm start (which just points to next start in the package.json) doesn't work as it complains about next not being found in node_modules (even though its there)

What do I need to do to get it work?

If I download the zip file and unzip it locally, it doesn't work either even though all the node_modules are there. I need to run npm ci to be able to get next start to work. How come?

Aren't I meant to just be able to copy node_modules across and everything should just work?

Also bonus points - do I need to force next to start on port 8080 on azure? The default port 3000 doesn't seem to work? And Azure docs say that npm install is run when package.json is detected. However that's clearly not happening either.

Any help and insights would be most appreciated!

1

There are 1 best solutions below

0
On

If anyone is trying to deploy Next.js SSR apps to Azure Web apps, the issue is the copying of the node_modules and the config of next.config.js

  1. I was using the File Copy task in my yml file. This isn't good enough. You have to use cp -paR node_modules to your artifact folder.
  2. We don't have a server.js file but you can't use serverless unless you create a server.js file :) So I changed the next.config.js to server and then it all works without a server.js file.