[nextjs] `nx serve project_name --prod` - does it support all features of `next start` ?
See original GitHub issueDocumentation issue
- Reporting a typo
- Reporting a documentation bug
- Documentation improvement
- Documentation feedback
Is there a specific documentation page you are reporting?
Additional context or description
We are using the nx nextjs package, and its working great for our development needs. Now we are trying to do self hosting in a nodejs environment and once we do nx build and then nx serve --prod, it runs the project fine. Note that we are not doing static html export. It will be a regular non-static site.
Now in nextjs documentation, https://nextjs.org/docs/deployment, it says the next start server supports all the advanced features that nextjs offers. We are wondering whether running our nx nextjs project using nx serve --prod provides exactly the same functionality that next start provides. We looked into the nx executors for nextjs, https://github.com/nrwl/nx/blob/master/packages/next/src/executors/server/lib/default-server.ts, and it seems to be spinning up an express server.
Hence our question is, after running nx build project_name, when serving via nx serve project_name --prod - does it support all features of next start ? If not, what is the recommended way to have all the extra features of next start ? Note that we have read about vercel deployment (eg https://nx.dev/recipes/other/deploy-nextjs-to-vercel) but we are not interested in vercel for this exercise.
Many thanks.
Issue Analytics
- State:
- Created a year ago
- Comments:5

Top Related StackOverflow Question
@bappy004 hey, yeah this is basically it. Only step extra is
rm -rf node_modules. There is no need to remove root level node_modules.And as I’ve mentioned, if you use “standalone” output from Next.js,
node_moduleswill already be output intoapps/your-app/.next/standalone. That way you can avoid this step where you install bunch of node modules again because you already have them installed at root level of your repo during build.It’s because it’s started from the root of the repo which contains all the needed dependencies (node_modules) to start the app. In production when you deploy the app, you don’t want to deploy your whole NX monorepo.
Yes and depending on your Next.js setup you might need to run
npm install(oryarn install) to install all required dependencies for that Next.js project before running thatnext startcommand.If for example you’ve used “standalone” output of Next.js, you should get all
node_modulesand get aserver.jsfile that you can just run usingnode server.jsif you wanted. https://nextjs.org/docs/advanced-features/output-file-tracingOnce you’ve built the app using NX, you want to handle the rest of the process as if you didn’t have NX at all. It’s just a matter of deploying that Next.js app after NX has built it and there should be tutorials online on how to do that.