Search code examples
buildnext.jsproduction

Minimum file structures needed for Nextjs on production


I'm struggling to understand the correct way or BEST WAY to deploy nextjs app. I have a hybrid Nextjs website which I currently host on Azure App Service. So far I run

  • npm build
  • npm start The app compile with no error and I host on Azure all the content of my application which contains
  • .next/
  • components/
  • pages/
  • ...all configs
  • ..all js files

Looking from Nextjs documentation (which is kind of slim on this topic), seems that this is the right way to do it. From my understanding tho, just the .next/ folder should be needed for production, since is the one that has bundled code. The pages/, components/ and so on, should be used just on development mode.

I also found some other examples online that go in this direction. If i try to remove /pages or /components tho, I got error and the app cannot run any more.

Can someone confirm me what is the minimum file structures needed for Nextjs application on production?

UPDATE:

The error I get is first: ENOENT: no such file or directory, i18n

When I add this file, then I get the error:

ENOENT: no such file or directory, pages/

i18n.js is a configuration file for the packages next-tralsation https://github.com/vinissimus/next-translate

I'm talking with the author there as well, it might be a problem on their end, but right now I just want to know if na hybrid Nextjs.js app in production should include pages/ folder. I want to know if .next/ folder is enough for production deployment and if not, i would like to understand why.


Solution

  • There is an example of usage with Docker in official repo https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile But I guess it applies for non-docker environments too.

    Basically, it builds application and only keeps this files and folders after that:

    • package.json
    • next.config.js
    • .env*
    • public
    • .next
    • node_modules

    So no, pages should not be needed after build for vanilla NextJs app, but it might be needed for something else maybe, like next-translate package in your example, I am not quite sure how it using pages and what for.