Enforce hoisting of some packages to fix giant disk size with Yarn
See original GitHub issueYarn has known issues deduplicating dependencies, sometimes failing to hoist dependencies shared between a ton of packages (such as babel-runtime
) and producing installs 5 times bigger than npm: https://github.com/yarnpkg/yarn/issues/2306.
While we could disable Yarn integration (https://github.com/facebookincubator/create-react-app/issues/1390), I’d like to explore an alternative approach. We should be able to determine which package causes most duplication, and then hoist it manually by making it an explicit dependency of react-scripts
. This would ensure Yarn deduplicates it. This is a temporary workaround until Yarn actually fixes the algorithm (tracked in https://github.com/yarnpkg/yarn/issues/2306).
Please don’t hesitate to help with this. You would need to:
- Reproduce the issue with giant (~1GB) install locally with Yarn.
- Figure out which dependencies get duplicated. (I don’t know the easiest way but you could probably look at Babel packages and see which dependencies end up in
node_modules
of each of them.) - Add the duplicated dependencies to
react-scripts
itself to hoist them. - Verify that the issue is resolved.
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (6 by maintainers)
Top GitHub Comments
I don’t mean to imply that I’m somehow more qualified to prioritize tasks than anyone else, especially @gaearon, but I fail to see why this issue is a big deal.
At the end of the day, disk space is cheap, this has no impact on build size or, if I understand correctly, build time. Its just feels to me like complaints about the size of node_modules are almost like saying “back in my day we used to walk uphill both ways to hand pick minified jQuery plugins and lovingly lay them down in the
vendor
directory.”Certainly this duplication bug is a problem that yarn should strive to fix, but I don’t really see how this matters enough to warrant temporary workarounds in CRA.
So I’ve done some investigation into deduping some of the dependencies:
Baseline:
Adding
core-js
as a top level dependency reduces the size significantly:Also adding
babel-runtime
reduces the size even further:Lastly if just
babel-runtime
(with a carat range) is defined then you get most of the benefits:From this is looks like the quickest solution would be add bothFrom this is looks like the quickest solution would be add justbabel-runtime
andcore-js
to react-scripts.babel-runtime
to react-scripts. What do you think @gaearon ?Node version: v6.9.0 Yarn version: v0.18.1 Operating system: Mac OS X 10.11.6