kyle-mccarthy / nest-next

Render Module to add Nextjs support for Nestjs
MIT License
644 stars 92 forks source link

Usage with Next@13 #92

Open yakovlev-alexey opened 2 years ago

yakovlev-alexey commented 2 years ago

At the latest Next.js Conf Next.js 13 was announced - https://nextjs.org/blog/next-13. It brings a lot of (experimental) changes including the introduction of Turbopack and (most notably) new routing system. You can check WIP documentation here - https://beta.nextjs.org/docs/app-directory-roadmap.

I figured it would make sense to create an issue where all observations and issues with nest-next used with Next.js 13 would get collected. As the issues arise and get solved (as well as the roadmap for Next.js get fulfilled) I will work on updating my tutorials and example repo.

I propose using this issue to discuss what changes need to be made in next-next to properly support new Next.js version.


From the brief experimenting I had (in a separate branch in nest-next-example) I discovered the following:

1) pages directory works as it did previously without (new) issues Can't really say much here - it works and thats fine 2) Turbopack can not be used with a detached server at the moment Official docs state that you may enable Turbopack by using next dev --turbo. However there is nothing on the topic of enabling it in a detached server (when creating a Next instance manually). I did not try looking at the actual sources for the Next server. It is possible that there is an option to enable it except it is not stated in the published types. Still I think it's worth creating an issue at Next repo. However I do not think it will break anything in nest-next 3) app directory can be used It will take some time to fully play around with and test all the new possibilities. The most important part is SSR and data fetching. I made the following observations:

I want to say that I am excited by the features brought by the new Next version and eager to see how they can be leveraged in Nest+Next stack. @kyle-mccarthy I want to ask you to share your thoughts on the new Next version and plans for this project in this issue as well. I may propose being a co-maintainer and introduce changes required for Next 13 since I have a bit of experience with nest-next and its code.

rubenvereecken commented 2 years ago

For what it's worth, I second @yakovlev-alexey as co-maintainer. He obviously knows his way around nest-next.

kyle-mccarthy commented 2 years ago

I would totally be open to making you a co-maintainer. Do you have any specific proposal in mind? Part of me wonders if setting up nest as a standalone application and exposing a router from nest-next to handle all the api routes would be best.

yakovlev-alexey commented 2 years ago

I would start by introducing a test suite testing the following:

It would also make sense to develop tests in such a way that would allow us to run them with specific Next versions (a new Nest version is unlikely in my opinion so no need to specify that). This will also open up the possibility to run CI in a matrix to effortlessly make sure all supported versions work.


Setting up Nest as a standalone application seems like a cool idea. Though I think it offers an entirely different approach to Nest and Next integration. Want to play around with this idea a bit and see how it could work.

In this particular case perfomance could also be important. From my experience debugging Next it strongly leans toward serverless. Even when running as a server (detached or not) it will dynamically require built pages (Next emits both server and client bundles for each page with server being the larger one with SSR methods and their deps). Running standalone could end up creating a new Nest standalone app for each request.

That might have changed since my testing but I believe Next maintainers are very opinionated on Next usage and as a commercial company try to sell Vercel deployment by not introducing features that would help using Next effectively outside Vercel.

Monkey-patching Next detached server could work...

I think it makes sense to create two new separate issues on tests and Nest standalone usage and continue conversation there. And keep this issue for Next@13 and app directory shenanigans.

TheLogan commented 1 year ago

I followed the tutorial, here https://dev.to/yakovlev_alexey/creating-a-project-with-nestjs-nextjs-3i1i

Is there a solution for the whole getting '[id]' rather than the actual id value in the query, yet? :) As in, my query is {id: '[id]'} rather than {id: 1}

yakovlev-alexey commented 1 year ago

@TheLogan id issue is fixed in #93

techeng322 commented 1 year ago

image

I have this issue now in Next.js 13.5.4

mansidhall-CAW commented 1 year ago

I am getting the same issue as @brittneytech818 While running next.js server I see no error, but while starting nestjs server I get this undefined nextConfig error for next versions 13.0 and above If I use a version lower than 12.0 then next is unable to detect @types/react So basically it works for only 12.0-13.0 (13.0 excluded)

yowayb commented 5 months ago

Does #111 fall under "app directory shenanigans"?