Does Next js production build need node_modules folder in the server?
After a bit of research, I am answering my own question. If you use getServerSideProps
you cannot static export your project. Therefore the node_modules folder is required to deploy the project on the server. That doesn't mean you have to FTP the node_modules
, you can do the npm build on the server-side which will download node_modules
to the deployment folder. In my case, the deployment folder weighs around 310MB where the node_modules
folder itself is around 300MB.
The latest Next.js documentation has a good example about how to create a standalone build with an excellent example of how to accomplish it with docker. As of now, the feature is experimental.
// next.config.js
module.exports = {
experimental: {
outputStandalone: true,
},
}
No, you don't need to add your node_modules
.
Would recommend you check out the docs about how to go about deploying your Next.js application, but in essence:
- run
next build
- run
next export
- deploy your
out
folder (default output folder, can be changed)
Alternatively, you can also use Netlify to deploy and host your application.