Home > Software engineering >  Next Js showing index of build folder when using serve
Next Js showing index of build folder when using serve

Time:12-23

i was trying to run build folder of next js , in react js when i run serve build it works perfectly. but in next js it just shows plain index of files in build folder..

enter image description here

What should i do to get proper results rather than index?

CodePudding user response:

serve only supports serving a static build of a site. So to build a static site in next.js you need to edit your package.json file like that:

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

Then you can try npm run build to generate the static build in the out folder which you can serve easily via serve out command.

Quoting from nextjs site @ https://nextjs.org/docs/advanced-features/static-html-export :

next export allows you to export your Next.js application to static HTML, which can be run standalone without the need of a Node.js server. It is recommended to only use next export if you don't need any of the unsupported features requiring a server.

Thanks.

  • Related