6 ms·
Ask HN: Why does React need 1484 dependencies by default?
Run
npx create-react-app my-app
and watch how it says
added 1484 packages in 1m
How in the world can this number of dependencies be considered sane and normal, and most of all, necessary?
What's more is that this barebone source code already takes up 235 MB (!)
What the ...? Is this what it takes to display some rectangles and glyphs in a browser?
- meiraleal 3y agoBecause react (and create-react-app, nextjs and alike) is terrible, old, badly maintained.
- shich 3y agoWhile dependencies can provide convenient functionality, the JS ecosystem has tended towards excessive granularity. Many packages contain limited code yet still require a large number of dependencies .. sometimes because of tooling (as in the example in the post here), but quite often out of convenience! Rather than hastily installing the latest shiny package, we should refactor and build reusable minimal utilities tailored to our domain.
- al2o3cr 3y agoHow in the world can this number of dependencies be considered sane and normal, and most of all, necessary? Wait until you find out how many parts are inside an internal combustion engine.
- jdthedisciple 3y agoNot the greatest analogy I've ever come across. Take a bicycle instead, and watch in awe how simple it is designed, yet how far it gets you ...
- canaus 3y agoAre you including the human-rider power source?
- kuekacang 3y agoSurprisingly, some bikes can be launched down on an inclined plane and kinda steer itself
- speedgoose 3y agoA bike still contains many complex parts and if you start taking into account what’s needed to build it, it becomes very extensive and rely on a long supply chain.
- jdthedisciple 3y agoEven if you reduced it to only the minimum parts necessary for it to function as a bicycle? Because my point was about what's necessary, not fancy add-ons.
- ironmagma 3y agoOr even just a house or bridge. Completely trivial-seeming things are just very complex.
- krapp 3y agoThe javascript ecosystem is unnecessarily complex. What would be a single library in any other language (including javascript, prior to NPM) is hundreds of separate single-line modules in JS, each likely with its own bespoke testing framework and toolchain. You have a package to test if a number is even that depends on a package to test if a number is odd that depends on a package to test if a number is an integer that depends on a package to test if a number is a number. And there's probably a whole-ass C compiler in there somewhere because why not? Whereas any other developer in any other language will just use a modulus and call it a day. Comparing that to the complexity inherent to an internal combustion engine or a house or a bridge is an insult to engineering.
- jdthedisciple 3y ago> You have a package to test if a number is even that depends on a package to test if a number is odd that depends on a package to test if a number is an integer that depends on a package to test if a number is a number. LOL, perfect summary of the SOTA npm ecosystem.
- moon_moon 3y ago[dead]
- ironmagma 3y agoThat makes for a great caricature, but React does not depend on `is-even`. As for the small modules, this is just the Unix philosophy lived out, "do one thing well," which is ironically what a lot of hardcore systems people used to preach.
- krapp 3y ago
- kristianp 3y agoIt does seem insane. Lots of small dependencies upon dependencies exponentially multipy
- jdthedisciple 3y agoYea, I just simply can't fathom how this can be considered necessary... Surely half of the stuff is not required for the basic react dev tooling to work?
- mhh__ 3y agoHate to say it but I get the impression (having learnt "hardcore" programming first then learnt react recently) that web dev struggles a lot from having smart-but-tasteless amateurs who don't know when to stop. That and npm has gamified the package registry so one is incentive to funnel as much shit as possible if one cares about these things.
- moon_moon 3y ago[dead]
- MrJohz 3y agoIt isn't required, but create-react-app (CRA) is designed as a kind of kitchen sink toolkit that includes a lot of things that you might not need now, but could need later. For example, while it doesn't include Typescript directly, it includes a lot of the tooling you'd need to get started with Typescript if you wanted to. Similarly with Progressive Web Apps, i.e. apps that run in the browser rather than natively, it includes most of the tools you'll need for that, and then allows you to opt in at any time. This makes CRA a good choice for someone trying to be particularly flexible, for example building an MVP or prototype where new features are going to be thrown in fairly randomly. But the cost is maintainability, particularly in terms of tending dependencies and keeping them up to date. A more lightweight version might be Vite. Vite does a similar job of bundling different tools together into a single toolkit, but takes a simpler approach using more modern technology. In my experience, you can get a long way just by installing Vite as a development dependency and React as a runtime dependency and going from there. This won't give you anything fancy like server-side rendering or routing, but it works for a simple application, and allows you to add in the extra tools when you need them.
- whatamidoingyo 3y agoThat's not _React_, that's `create-react-app`, which was built long ago, and isn't really used so much today for starting new projects (for obvious reasons). (In fact, it's considered deprecated) Check out Vite: https://vitejs.dev/ https://vitejs.dev/ `npm create vite@latest` run through the process --> `added 217 packages`
- jdthedisciple 3y agoNot really on topic but I mean I would usually go with NextJS since it just works so well with Vercel, providing a really convincing, complete solution. But I will check out Vite nonetheless, curious how it fares against it...
- whatamidoingyo 3y ago> But I will check out Vite nonetheless, curious how it fares against it... It is 100x better. :)
- jdthedisciple 3y agoWait upon quick glance Vite doesn't come with SSR support ... ? Yea guess I'll stick with NextJS
- ironmagma 3y agoSSR support is only needed for public-facing websites that will undergo some kind of search engine indexation. For most apps this is not necessary since most apps are not accessible publicly.
- verdverm 3y agoNextJS does more than SSR, like determining routing based on directories and making React Server Components and Actions so simple it's hard to not choose NextJS They've removed a ton of pain from full stack React/JS/TS
- praet 3y agoCreate-react-app has a whole bunch of extra stuff, like a testing library, various styling engines, HMR and other build tools that aren't included in your deployed code anyway. Production React, on the other hand, appears to only have 2 deps: js-tokens and loose-envify
- super256 3y agoThat's not React. The stuff you need for "displaying some rectangles and glyphs in a browser" is "react" and "react-dom". Those 1484 packages are simply for the build step. And having a lot of dependencies in a build tool isn't necessary "insane".
- tracker1 3y agoI'd probably start with vite or parcel, vitest and biome. This is for build, test, formatting and linting. Otherwise,. Just use HTMX if you want to minimize your JS footprint.
- dalmo3 3y agoIt's the same reason as why it's so slow: the shadow DOM. The shadow DOM consumes 80% of that disk space. 49% is dedicated to box-shadow alone.
- rabbits_2002 3y agoThat is create-react-app not react itself but I agree webdev has reached a point of schizophrenia regarding dependencies and performance.
- he11ow 3y agoAccording to the latest Stackoverflow developer survey, 40% of developers use React, well above any other web framework. (42% for "professional developers"). It doesn't answer to your question, but it does answer to mine on these flexes in HN around niche frameworks and the difficulty of putting them into context. I'm glad people are working on alternative solutions, and maybe ten years from now everyone will be using something else. But right now, 235 MB is an awfully small price to pay for something that just works, especially as a lot of it doesn't actually show up in deployment.