Deploying a small sized Next.js project with SSR
See original GitHub issueHello team! I need urgent help. I am using NX monorepo for my current project where I have a next.js dashboard app located in /apps/dashboard , this app is widely implementing the SSR feature using getServerSideProps. I am trying to deploy this next.js app (dashboard) to production. I have used yarn build and yarn serve and everything went smoothly, however, I want to deploy it without having all the node_modules and the whole monorepo. I tried making a standalone build but that didn’t work, i got the same issues in here. Currently I want to deploy to Azure using a docker container, and I am really looking for a small size docker image. I need your help. Thanks !
Current Behavior
Can’t build a standalone next.js app. Unavoidable bloated node_modules folder.
Expected Behavior
Steps to Reproduce
Build the app using nx build
yarn nx run dashboard:build --configuration=production
the build output will be in dist/apps/dashboard
, however, this can’t be run by it self, it needs the whole nx monorepo packages.
my run command yarn nx run dashboard:serve --configuration=production
This issue may not be prioritized if details are not provided to help us reproduce the issue.
Failure Logs
Environment
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:6 (2 by maintainers)
Hey! Thanks for opening this. When it comes to deploying next apps, using Nx, Vercel is first class. Here is our guide for it: https://nx.dev/guides/deploy-nextjs-to-vercel#deploying-nextjs-applications-to-vercel Artifacts inside
dist/apps/<app>
are self-containted so usually you should be able to deploy that folder and runnpx next start
from it. We will look into other deployment targets, as currently there maybe a few issues left to be ironed out.For building a docker image with NX and NextJS and to maintain a small image size, I would recommend using this in your
next.config.js
:This should dramatically decrease your image size and in addition, you do not need to do a
npm install
in the built standalone build. The package.json is incorrect however the image size is small and the application should work withoutnpm install
so the package.json should not matter really. For the Docker file, you can basically copy the standalone files over and that should be it.