Skip to main content

Command Palette

Search for a command to run...

Opinion: You don't need Create React App

Published
3 min read
Opinion: You don't need Create React App

React is an incredibly popular library for building user interfaces.

Equally ubiquitous is Create React App, the tool which provides you with a fully functioning React application from a single command. Create React App is great for tutorials and hobby projects because it gives you a huge amount of configuration and functionality for very little effort.

However, CRA's greatest strength is also its greatest weakness: it obscures far too much complexity.

This is fine, so long as you are happy to treat CRA as a slightly magic black box. If you want to understand what's going on inside or configure something slightly differently then you're going to need to need to eject.

CRA eject is not for the faint-hearted; it results it a significant amount of additional complexity in your repository. Try it yourself, instructions below, or here is one I made earlier.

npx create-react-app my-app
cd my-app
npm run eject

A quick glance through the config folder, the scripts folder, or even just package.json will quickly demonstrate just how much has been set up for you. Do you understand it? Do you need it? I don't think I do, but not knowing is a bit barrier to ejecting.

Fortunately, there are alternatives.

The core functionality I want for a build tool is to make the process of turning the code I write into code that can run really, really, easy. This means I want it to handle: running a local dev server and making a production build.

At the moment I prefer to scaffold new React projects using Vite. It is a much more focused build tool, and it is just as easy and quick as CRA:

hereward@manticore:~/code$ npm create vite@latest
✔ Project name: … vite-project
✔ Select a framework: › react
✔ Select a variant: › react-ts

Scaffolding project in /home/hereward/code/vite-project...

Done. Now run:

  cd vite-project
  npm install
  npm run dev

That's it. Vite sets up three scripts in your package.json: dev to local development, build to create a production build, and preview to build for production but serve locally. Notably, it's not set up linting or testing. It's also not expressing any opinion about how you apply styles to your application.

Vite itself does hide the complexity of how it does this, so is technically a "magical black box", but a far smaller one that CRA, which I think is helpful.


Vite is by far from the only tool you can use to build a React app. There are alternative approaches you can take:

  • ParcelJS adopts a zero-config approach to build set-up, it should Just Work.
  • If it you want go one to level deeper then under-the-hood Vite uses rollup.js and esbuild, which you can configure directly.
  • You can also stick to more traditional tools like webpack, using something like Create App to help generate the required configuration.

// Versions used when writing this article
"vite": "2.8.0"
"react-scripts": "5.0.0"

With thanks to @CheshireSwift and @fildon_dev for their feedback ♥. @fildon_dev also writes as Rupert 'fildon' McKay.

V

I'm currently learning React by using CRA and I do find the process quite complicated and obscure.

I also get the impression that CRA is sort of a beginner's guide or a tool to quickly build something. The React library itself is what you'd want to use in most cases. Not sure if I'm correct about this, just an impression.

H

Apologies for leaving this unanswered for so long.

Thinking of CRA is a beginner's tool is probably helpful, it sweeps a lot of the set-up away so you can just start learning React. This is helpful. Unfortunately, CRA also gets used as the basis for many professional projects, which is less helpful.

You're correct that the React library itself is what's needed to actually get the functionality of React. However, it's not (necessarily) sufficient by itself. Most React code involves writing JSX, code which looks like HTML but isn't. JSX cannot be run by browsers so a tool like webpack is required to transpile that code into vanilla JavaScript that the browser can run.

R

Strongly agree. Every project I've ever seen use CRA has eventually had to wrestle with its constraints and sooner or later they have to make the hard choice to eject or not. Either way, they seem to regret it :-D

1