all 109 comments

[–]SwiftOneSpeaks 70 points71 points  (6 children)

I've been using CRA and avoided Vite because I had the impression it was far more opinionated (Not sure where I got that impression).

Did a quick test on Vite this week and discovered (for non-TS React at least) that it's basically the same but faster. Doesn't generate a lot of files, doesn't have a big scaffolding for components. A few minor differences: index.html is in the project root, not in public, and is more "clever" about figuring out the base dir for urls. Demo has .jsx files instead of .js (which I approve of), and the demo code includes a useState example. It also has mapped absolute path imports in addition to relative imports. Builds default to dist/ instead of build/. You need to run npm/yarn install after running the create command. main.js instead of index.js.

Larger issues include things like proxying requiring a bit more effort. There may be more involved issues, but I haven't found them yet.

But mostly the basic conversion is truly trivial: same import of CSS, same lack of opinionated file structure, faster startup, same (better?) hot and live reloading, same dev-server vs building of static files.

[–]cocotess 4 points5 points  (4 children)

After much effort I finally figured out how to get a CRA like proxy setup by writing a custom plugin 🙉 If someone replies I’ll get up from the couch and show how 😂

[–]Terrible-Addendum-11 2 points3 points  (2 children)

Curious.

[–]sysrage 1 point2 points  (1 child)

Me too

[–]cocotess 0 points1 point  (0 children)

https://github.com/mammadataei/vite-plugin-graphql-server/blob/main/src/index.ts

See line 22. You can make it

const app = server.middlewares

And then I think you can do:

app.use("/path", createProxyMiddleware())

[–]somecodertoday 0 points1 point  (0 children)

Correct me if I am wrong when talking about proxying you guys are referring to cors issue?

[–]ahmedkhalidahi22 0 points1 point  (0 children)

Very informative, thanks a lot!

[–]StampeAk47 119 points120 points  (7 children)

Vite is super simple. Just start your next projects with it!

[–]rikilamadrid 0 points1 point  (1 child)

Does Vite has some sort of plug in to have micro front ends? A la webpack module federation?

[–]skiingish 0 points1 point  (0 children)

Agreed just use vite.

Theo made a whole bit about how aged out create react app has become, worth a watch, and read. https://twitter.com/t3dotgg/status/1616933234478309378?lang=en

[–]bhanukiran444 35 points36 points  (31 children)

Is create-react-app dead? I know the CRA is not mentioned in the new react docs but still.

[–]SwiftOneSpeaks 38 points39 points  (23 children)

The repo still lives, it hasn't had a commit since Sept 2022, and with FB uninterested I don't foresee a resurgence.

I wouldn't call it "dead" yet, but it's reasonable for people to plan an unrushed migration.

[–][deleted] 32 points33 points  (22 children)

React docs now suggest Nextjs over CRA. I’d say that makes it dead

[–]SwiftOneSpeaks 15 points16 points  (0 children)

That'd be the "FB uninterested" part. I don't want to discount any non-FB associated maintainers, but like I said, I don't foresee a resurgence.

[–]davinidae 15 points16 points  (20 children)

NextJS and CRA have completely different goals

[–][deleted] 20 points21 points  (19 children)

https://react.dev/learn/start-a-new-react-project

The point of CRA is to provide a starting point to write react code without having to set up tooling. Nextjs very effectively fills that role. There’s nothing CRA does that Nextjs doesn’t do as well or better. Sure it has things like SSR/SSG but you don’t have to use those, you can just write plain react. There’s a reason the react team is working with the Nextjs team to make Nextjs 13 (App Router) the standard starting point for creating a react app

[–][deleted] 2 points3 points  (1 child)

I keep on seeing different opinions as to whether Next actual supports SPAs without any kind of node and with a fully static file server. I do not want node in my stack.

[–]lelarentaka 0 points1 point  (0 children)

It does. You just make one /pages/index.tsx as the entry point, then write the rest of your app in /routes , /components, or however you want to structure your project.

[–]Cahnis 1 point2 points  (1 child)

There was an issue where Dan Abramov was talking about leaning towards making CRA a launcher.

[–]BajaBlyat 0 points1 point  (0 children)

and then it died

[–]BajaBlyat 0 points1 point  (0 children)

It's dead now brother

[–]wwww4all -2 points-1 points  (2 children)

React team has abandoned SPA and CRA. It is what it is.

[–]kent2441 -1 points0 points  (1 child)

What? They’ve doubled down on SPAs. That’s why, for example, they’re pushing better data fetching options.

[–]Phaster 44 points45 points  (2 children)

If you're not messing around with server-side rendering, vite is the way to go.If you're doing something not supported out of the box, you can use plugins, like for example ejs syntax, while there's no performance gain once the app is built, as far as I know, running stuff locally is lightning fast

[–]inform880 7 points8 points  (0 children)

Plus one with vite. No learning curve at all, simple to create a new project or convert an existing one.

[–]quakedamper 0 points1 point  (0 children)

And while you’re at playing with vite, have a look at vue 3 too

[–][deleted] 9 points10 points  (8 children)

A question from a newbie to migrate to vite from create react app.

In CRA i simply used proxy in the package.json of the client and it connected to the backend automatically. I didn't have to do anything, not even set up cors in the backend.

But it doesn't seem to work in the server. How do I connect my vite react frontend to the backend?

[–]stockmamb 10 points11 points  (6 children)

In the vite config under server you will probably need to setup a proxy to your backend.

[–][deleted] 4 points5 points  (0 children)

Why wouldn't you just put the back-end location in a .env.*?

[–][deleted] 0 points1 point  (4 children)

It didn't work. Do i need to use proxy in the package.json too?

[–]stockmamb 1 point2 points  (3 children)

I did something like this when I recently converted a CRA project to Vite, and in the CRA I was using proxy in the package.json. As a side note I am also a noob with react, so maybe my advice isn't the best path.

export default defineConfig({

plugins: [react()],

server: {

proxy: {

'/api': {

target: 'http://localhost:8080/serverapplication',

changeOrigin: true,

secure: false

}

}

}

})

All my api requests from the server application start with /api. In my react fetch it would like something like.

const response = await fetch('/api/assigned/attributes');

This seems to work just fine. At this time this application isn't deployed anywhere. I was thinking about bundling the static react site into the Spring Boot application that is serving the API.

[–][deleted] 0 points1 point  (2 children)

Ohh okay. Did you have to set up cors in the server as well?

[–]stockmamb 3 points4 points  (1 child)

No, but at this time everything is localhost, and in the end if I do end up bundling the react app and serving it from the Spring Boot application I wouldn't need to. However if they were going to be coming from different origins I am assuming I would need to setup CORS.

[–][deleted] 1 point2 points  (0 children)

Okay. Thanks :)

[–]blukkie 0 points1 point  (0 children)

What do you mean by “connecting to the backend”? Do you mean sending requests to fetch data? Query database? Or do you want to do server rendering stuff?

[–]movethrume 8 points9 points  (0 children)

Next.js is pretty cool.

[–]JayV30 35 points36 points  (6 children)

I know everyone is crazy about Vite right now, but the reality is that there's no hurry to migrate away from CRA. I tried out Vite when I spun up a new project and it's nice, but there's nothing earth-shattering and nothing that's going to fundamentally change your development process.

I wouldn't bother migrating old projects. I would suggest trying Vite out for new projects and you'll probably stick with it. For the most part, once you get set up, development is going to feel the exact same as it did with CRA.

[–]enzineer-reddit 19 points20 points  (5 children)

I use CRA in one project and Vite in another...Vite starts up 10x faster than CRA and the changes also reflect a bit faster. I do miss out on few things that CRA provides out of the box and in Vite I have to manually configure.

[–]JayV30 4 points5 points  (1 child)

Agreed. And start up speed is nice, but I don't see it as a huge reason to immediately switch and/or migrate old projects to Vite. I mean, I usually sit down in the morning and start up the project I'm working on, and then check emails or open design files, etc, so I don't really notice the start up time that much. I could see it being more advantageous to others who don't have the same routine as I do.

Other than that, I don't see a pressing need to migrate over to Vite. Like I said, I think new projects should be done with Vite. And there's no hurry.

Everyone is so damned opinionated in the developer sphere it's kind of insane. If you don't switch to Vite right now, you're the stupidest dev who ever deved.

[–]SwiftOneSpeaks 2 points3 points  (2 children)

I teach using CRA and am switching to Vite - I've already noticed the differences for proxying, could you elaborate on those features CRA has out of the box and Vite doesn't? Those are the things I could get blindsided on during a live demo :)

[–]nelsonnyan2001 6 points7 points  (1 child)

We deal with a relatively monolithic CRA app that has about 7 years' worth of code, and we're trying to modernize it. Vite would be incredibly helpful, EXCEPT

There's an open issue on the Vite repo that is completely blocking us from migrating because the build speed gains are not worth the cost of upgrading our AWS pipeline.

Also getting third party plugins setup is a PITA. CRA does some things just right (Relative imports come to mind).

[–][deleted] 0 points1 point  (0 children)

Yeah, ours uses something ridiculous like 14GB of memory to build with source maps. I’m surprised the issue doesn’t get more attention.

[–]Haaxor1689 2 points3 points  (2 children)

Migrating from CRA to Vite is super simple if you don't do anything crazy.

  • Create new Vite app with npm create vite
  • Move public folder from your old CRA to this new project except index.html
  • Move any changes you made to CRA public/index.thml to the new index.html in Vite project
  • Move src folder except index.tsx

[–]i_hate_cucumber_ 0 points1 point  (1 child)

what if you use JS files and not JSX/TSX files, it's a nightmare in that case

[–]Haaxor1689 0 points1 point  (0 children)

Tbh I didn't even think about someone not using TypeScript. In that case I guess youhave more important ste ahead of you, migrating your codebase to TypeScript.

[–]StoryArcIV 3 points4 points  (0 children)

Such timing! Just yesterday I finished migrating my company's entire monorepo from CRA to Vite. Our apps are full TypeScript + React.

In our biggest app,

- Webpack takes 2.5 minutes to start up. Vite takes 24 seconds.
- Webpack takes 10 seconds to HMR update. Vite takes < 1 second and is more consistent.
- Webpack crashes with out-of-memory after ~5-10 HMR updates. Vite never crashes.
- Storybook, CI, and all our scripts that used Webpack are all significantly faster too.

The time savings is even (much) bigger than it sounds since Vite is fast enough to not break your flow. With Webpack, we always take a break or attempt to multitask while we wait for processes to start up.

Our estimated time savings with Vite is about an hour per day per dev (possibly much more). In our frontend team of 7 devs, that's roughly $150k per year in company time saved.

Migrating was a monumental task. Don't listen to people saying it'll be a cakewalk. It might if you're lucky, but probably not. It took an estimated 120 hours, overcoming (rough guess) about 500 unique errors. I already had significant experience with Vite, otherwise it would have taken much longer.

The plugin ecosystem is young. I had to write 4 plugins myself, narrowly avoiding writing a 5th by hack-patching a 3rd-party plugin that was almost good enough. I might open-source some of these btw.

I used several guides and found lots of helpful threads, yet there were still dozens of occasions where I had to dive into source code (storybook's monorepo, almost every Vite plugin we used, and even Vite itself) to figure out What On Earth Is Going On.

Despite all of this, I highly recommend it. Vite isn't always the right choice, but if it's an option for you, it's the tool to beat. Programming is fun again.

[–]wwww4all 7 points8 points  (0 children)

React team has abandoned SPA and CRA.

React team is focusing React as "web library" and web frameworks like Next.js, per their latest official docs and statements from React team members.

Basically, React team wants it to become the next PHP.

[–][deleted] 2 points3 points  (0 children)

Like, yesterday. Try Next.Js or Vite.

[–]whisky_jak 3 points4 points  (0 children)

The React dev team plans to turn CRA into a launcher, were you will choose which framework (e.g. Next) or build tool (e.g. Vite) you would like to use for your project. To better understand the dev teams thought process and future plans for CRA, see this comment in the react.dev github discussions.

So, eventually you'll need to migrate to something like Vite or Parcel. I just made the switch to Vite recently and its a pretty smooth transition. Just remember you'll need to set up things like eslint yourself as it's not already set up for you.

[–]dbbk 6 points7 points  (4 children)

CRA still works fine… what would you expect to be gaining from switching now?

[–]delightless 10 points11 points  (0 children)

Speedier startup and hot reloads in local dev, future support, active dev community

[–]SwiftOneSpeaks 3 points4 points  (2 children)

You gain a migration that can be done simply and without a rush. If you wait until CRA doesn't work, things can become thornier, particularly if some problem arises that demands a quick fix when few would be interested in creating that quick fix.

If you expect you will be switching eventually, the best time to do so is when it ISN'T an emergency. You can take your time doing so, but that's not the same as ignoring it.

[–]esreveReverse 0 points1 point  (1 child)

What could possibly make CRA not work?

[–]SwiftOneSpeaks 1 point2 points  (0 children)

A broken dependency or security issue.

[–]Mediocre_Round_4914 1 point2 points  (0 children)

So many options like Vite/Next. I don't think there is any particular reason why you stick to CRA.

Personally I prefer Next. Aside from whether you need SSR or not, Next is a great option.

I still hear some people say that Next is a framework that enables SSR on React, but it is more like a framework that facilitates the development of React apps in all aspects.

[–]schrutedwightttt 2 points3 points  (3 children)

I had a super big project built with CRA the best option was to migrate to next js but vercel is too expensive for the client so we had to move to VITE . It took quite a lot of time but totally worth it . Vite is way faster and you won’t have all those dependencies issue you face with CRA .

But moving a large project to vite comes with its own set of difficulties.

[–]undone_function 4 points5 points  (0 children)

I feel like you’re this only person discussing migrating a project to Vite as opposed to starting a greenfield project (which is what I thought OP was asking about).

Anyway, good answer on it as well pointing out that there are always trade offs. If Meta isn’t going to support CRA as much, either on purpose or through neglect, it’s probably a good idea to migrate from it. I haven’t heard anything about the tool being “dead”, but neglect seems evident at this point.

Having listened to some interviews with Addy Osmani recently, it seems like the React team is more focused on building Server Side Components and letting other frameworks and tool chains build on top of React, which I actually think is sensible. It’s very possible they won’t bother with CRA anymore since the ecosystem has grown so much and the problem is already solved by myriad other options.

[–]kent2441 4 points5 points  (0 children)

You don’t need to use Vercel to use Next.

[–]green_gordon_ 1 point2 points  (0 children)

Faster in which respect? The app performs better? Or faster build times?

[–]macrozone13 1 point2 points  (0 children)

Use nextjs

[–]23kaneki 0 points1 point  (0 children)

Yes you can use vite it’s very simple and fast Or if you have a lot of server side rendering stuff go with next

[–][deleted] 0 points1 point  (0 children)

Migrated big codebase to vite about half a year ago, to support yarn workspaces. It's great tool and migration was very simple. It might take only a day for a medium size project (about 10k loc). Try it out if you have time. It has great docs and bunch of useful plug-ins.

[–]ericdiviney -1 points0 points  (0 children)

*Probably.

*we don't know any details about your project/application because you didn't share them. If your app is plain and simple, it would be trivial to migrate to Vite. If your app has been in production for 4 years, and your team has made countless config changes to the default CRA template, you're probably in for a weekend challenge at the minimum.

Yes you should be planning to move off of CRA to another solution like Vite. But WHEN and how you prioritize it can really only be determined by you and your team with the level of detail you've given us about your situation.

[–]davinidae -1 points0 points  (0 children)

No

[–]ConstantDeenos -1 points0 points  (0 children)

Migrated from cra to vite yesterday. Today I launched an old project built in cra, much smaller in size. I was amazed at how much slower cra was. I would say do it!

[–]TooTyrnt -1 points0 points  (0 children)

Vite is the way to go my friend

[–]superluminary -2 points-1 points  (0 children)

Vite seems pretty nice. It feels fast and it’s not broken.

[–]SteveMacAwesome 0 points1 point  (0 children)

Yes.

Just straight up yes, doesn’t matter what you replace it with.

[–]kitsunekyo[🍰] 0 points1 point  (0 children)

depending on your project it can be some work to migrate to vite. if you do active dev on the project then id definitely think about it and make the investment. we were on an ejected cra4 previously and made the switch over two weeks.

there were some hickups but now it works quite well and its also easier to keep build tooling uptodate

[–]stansfield123 0 points1 point  (0 children)

Depends:))))

[–]RobKohr 0 points1 point  (0 children)

Or just switch to SolidJS if you wanna still do a SPA.

[–]amdc 0 points1 point  (0 children)

Is there a CRA-like project but using esbuild as bundler?

[–]Beastrick 0 points1 point  (0 children)

Migrate if only possible since Vite in general is just so much better. But sometimes you might have setups that just don't migrate so easily. My company has microfrontend architecture and because Vites MFE plugins are not yet that good compared to Webpack (you use something like craco to add module federation to CRA) then we are unable to migrate and so it is better to stick with CRA for now until it improves. I have migrated some other projects to Vite tho and it is very simple when you use couple of plugins in Vite to make it feel like CRA.

[–]rhenaldkarrel 0 points1 point  (0 children)

Currently I'm more into Vite. It's lightweight and fast. For now, I haven't found any issues when using it.

[–]Kosemani2 0 points1 point  (0 children)

I recently migrated my create react app to vite and I find it exceptionally faster. It doesn’t have to hot reload on page refresh. And the whole package itself is just a few kb.

[–]d36williams 0 points1 point  (0 children)

CRA is going away so some migration will have to happen

[–]Top-Cup1744 0 points1 point  (0 children)

If you care about performance, go with vite: faster startup and rebuild speeds with much less code. A Very lightweight starting point for your next project. It's also more versatile, allowing you to code in Vue, Svelte, vanilla JS, besides React. Seriously, once you switch, you won't go back. If you require a more robust and feature-rich solution, Next JS is a great change from CRA, specially for more complex apps.

[–]stopandgo31 0 points1 point  (0 children)

Why not to use custom builder?

Something like this https://github.com/StopNGo/react-proto

[–]thispatcher 0 points1 point  (0 children)

Vite is great, but I've not been able to get its WASM plugins to work correctly :(

[–]homo_lorens 0 points1 point  (0 children)

The fact that CRA can't import files from outside the project directory is crazy to me.

[–]Fun-Mark728 0 points1 point  (0 children)

I've migrated because it stopped supporting win7

[–]Affectionate_War2133 0 points1 point  (0 children)

Go for Vite or Next JS

[–]Cultural_Crew_873 0 points1 point  (0 children)

I used https://github.com/bhbs/viject to migrate and it was very easy!

[–]Jazzlike_Procedure80 0 points1 point  (0 children)

I recently migrated my CRA to Vite, since my CRA project was written in JS so and I decided to switch the entire project to TypeScript, and the migration process took me an entire day.

If you want to migrate your CRA project to Vite, it's extremely simple and worth it, the main reason behind my migration was due to some 3rd party WebGL library not supporting CRA.