Don't use NextJS to replace CRA
Tags: react, nextjs, vite, webpack
Published: 2023-10-04 19:34:25

I'm probably going to get heavily bashed for this, and  I don't really know how to start this post so I'll just go ahead and straight up declare the important part of my point of view: I think it's abhorrent that after declaring that create-react-app was deprecated and should no longer be used, the React team decided that beginners should be using NextJS. By that, I mean, the [Start a New React Project page](https://react.dev/learn/start-a-new-react-project) lists NextJS as the first, primary way to create a project, followed by Remix and then Gatsby. 

Why am I angry about this? Because it's not correct. Developers that were previously using the create-react-app ("react-scripts") method based on webpack were all very quick in realizing that the proper alternative was to use ViteJS. Implementing Vite in our existing react projects was pretty trivial, with the biggest difficulty being the fine-tweaking of the vite.config file to have the same functionality as our old webpack configs: aliases, plugins, transformations, etc. 

Sure, some of us had the pleasure of updating dependencies like node-sass. Some had the difficulty in updating to node 16 and then node 18, due to environment restraints. But overall, from personal experience, moving to Vite was a breeze. Creating new projects is also almost trivial with Vite since it supports so many things out of the box...

So pray tell, why the hell is the very _mention_ of Vite burried inside a "Can I use React without a framework?" block that's not expanded by default, lumped in with parcel, talking about "rolling your own custom setup by grabbing react and react-dom, then adding vite"? As if it wasn't just a simple question of running `npm create vite@latest my-react-project`, choosing "React" in the list,  then completing a few other simple questions and being ready to roll.

But why am I _really_ angry about this, though? Well it's because a lot of time on Discord, on programming servers, helping other people, especially beginners, in their development journey. And let me tell you, there has been a massive shift in help questions every since CRA got deprecated and NextJS put front and center. I'm answering a hell of a lot more questions about routes, server side rendering, "hydration" errors, and how to "connect nextjs to my express backend", than I was before. Those people, those (often) teenagers asking for help, don't even know that NextJS being full stack implies that it has a backend. They're confused about how they can deploy a simple front-end app to their static host or to github.io. They don't understand hydration problems, and shouldn't, because they're just trying to make a front-end and they've been coerced into choosing the wrong tool for the job they're trying to do.

I'm not saying that NextJS is bad, per-se. Personally I've found it  to be on the overengineered side, and my only foray into adding authentication was a disappointing failure due to next-auth's exceedingly opinionated defaults... But I would still give NextJS a very good look if I really needed to add some Backend-For-Frontend feature, or some middleware, or some SSR features to an app.

It's not that NextJS is wrong. It's that it's the wrong choice to replace create-react-app. 

Tell me how I'm wrong in the comments, I'm open to competing points of view!