7 ms·
Huge no. of files for Angular 2
- justinsaccount 10y agoThis person is counting the node_modules directory. While JS is a bit insane and this directory will have a ridiculous number of files, they are concerned: "because my deployment (google app engine) allows only 10K files" meaning, they don't realize that node_modules is for development and not related to the application they would actually deploy.
- DHMO 10y ago> and not related to the application they would actually deploy. this. Granted, it's the same with everything- if you expanded every compressed file and counted every class, most languages and frameworks would just be incredibly nuts, because all of them aren't needed. But, something could be done about that; you could better differentiate what is there for convenience, and what needs to be there and make the developer more aware of what they are using. It can make development more difficult if done poorly, but good examples of minimalist development are out there, e.g. Sinatra and similar frameworks that said X is too much- just use this.
- sotojuan 10y agoHope this comment stays at the top before all the "wow JS sucks!!!" people arrive :-) Though to be fair a "modern" JS dev environment does use a ton of stuff! IIRC Angular 2 production builds are actually pretty efficient.
- merb 10y ago> Though to be fair a "modern" JS dev environment does use a ton of stuff! Though to be fair a "modern" JS dev environment does use a ton of unnecessary stuff! I fixed your comment.
- sotojuan 10y agoEh, transpiling ES2015+ to ES5 is not unnecessary if it makes you more productive—Babel is just really big.
- Klathmon 10y agoWell to be fair, does anyone expect a compiler to be small?
- sotojuan 10y agohttps://gitlab.com/Rich-Harris/buble https://gitlab.com/Rich-Harris/buble Buble says "Files (940 KB)" but it doesn't do everything Babel does (just a strict subset).
- Klathmon 10y agoI know that it's possible, but what's the purpose? Is anyone's quality of life really impacted by the size of babel vs buble? Does the size of a compiler really change anything for the average developer (obviously within reason)?
- sotojuan 10y agoI personally don't care but I've had super long install times when using slow internet—which in many parts of the world is the standard speed. I'll keep using Babel, but I like that there are alternatives that install faster if need be.
- Klathmon 10y agoI agree. Also there are multiple ways that you can install these things. The "recommended" way is to install babel for each project independently. Space is cheap, internet speeds are fast for many, and avoiding version issues outweighs the savings. But you can install globally, so you'd install babel once and can use it in all projects that way. Then throw in the possibility of different package managers and you get a crazy amount of freedom and choice. People get overwhelmed with "javascript fatigue" and I just don't get it. You don't need to do everything, but having the option to is amazing.
- Svenskunganka 10y agoIIRC the Angular2 production builds are the largest among all the frameworks. If you add the router it sits just shy of a meg - and that's just the dependencies. Not sure if they've started working on bringing the size down yet, but there are 1KB alternatives[1] for those who cares about their users. [1] - http://monkberry.js.org/ http://monkberry.js.org/
- vbernat 10y agoThis website froze my Firefox running on an i7 CPU due to the animated background.
- emodendroket 10y agoI'm not sure the right conclusion here is "oh, well then that is reasonable."
- douche 10y agoHas npm finally figured out how to de-dupe dependencies? In one project, I have something like 47 copies of the same version of the same library, distributed at all levels of the node_modules hierarchy. I try not to think about that JS tooling too hard, lest I start pulling my hair out and devolve into a screaming crazy person.
- rplnt 10y agoThis sucks so hard. It's also quite easy to hit path length limits for certain operations (on windows) when you have this mess there.
- dgorges 10y agoTotally. We just ran into this issue. Running npm install inside a linux vm resulted in an endless loop, because the nfs mapping created path names that exceeded the length limit.
- ishener 10y agoit's like an entire eco-system is fundamentally broken
- fahrradflucht 10y agoMaybe, but it's not like there is no way of solving that issue. It's just that this problem can't be solved entirely by npm. Node has to make changes to it's module loader as well.
- throwanem 10y agoNPM 3 tries, not entirely without success, to flatten the tree under node_modules/; I've had good results using it to resolve the kind of path length issues (in this case, with NTFS directories mounted in a VM) that you describe. Might be worth a look in your case as well.
- SquareWheel 10y ago
- ishener 10y ago32,000 files for a hello world... jeez, i'm going back to java.....
- j_jochem 10y agoNot a lot better: $ unzip -l /usr/java/jdk1.8.0_77/jre/lib/rt.jar | wc -l 20138 It's just less of a burden on the host filesystem because those files are usually loaded straight from the jar (i.e. zip file).
- deleted 10y ago[deleted]
- j_jochem 10y agoAlso note that this is only the standard library. If you add an enterprise framework you're probably pushing 50k.
- ivan_gammel 10y agoJRE is a platform, so if you counting platform files, why not also counting NodeJS or browser sources too? I'd rather look at comparable thing like JEE server + Spring + some server-side renderer like Thymeleaf.
- marpstar 10y agoI'd argue that Angular2 is a platform as well.
- smrtinsert 10y agoYes, let's compare the industrial strength tested jdk with the average npm lib developer.
- stupidcar 10y agoNo, 32k source files for the whole Angular 2 SDK. The deployable hello world app would be one JS file. Try exploding every Jar in the JDK and counting how many class files and resources there are.
- agconti 10y agoEvaluating a framework by the number of files its dependencies are broken into is a a pretty poor measure of quality.
- huuu 10y agoWhy? If framework X does roughly the same as framework Y which is 50% in size then you can estimate that the code of Y is more effective.
- sambe 10y agoNumber of files is not the same as size, especially with the way node modules tend to be structured.
- fuzzy2 10y agoInstead of "50% in size" I'll assume "50% fewer dependencies", because I think that's the point here. I believe that creating a module without relying on other modules will likely lead to reinventing the wheel. Well, lots of wheels. However, that might still be fine. But what about that one corner case you missed? It might already be solved in a third-party module that focuses on one thing only. It's really not that bad to try and use specialized modules as much as you can. You can benefit from other people's cleverness and focus on more relevant work. Yes, there will probably be a lot of on-disk overhead. But is that really relevant today?
- Klathmon 10y agoThis is the major part of the whole "left-pad" fiasco I don't get. If there is a well written, well tested, and widely used micro-library out there that does one thing and does it very well, why not use it? Even if you think you can re-implement it in 5 minutes, will yours be as fast? Will yours be as well tested? Will yours have an interface that many other developers already know and use? Sometimes reinventing the wheel is needed, but most of the time using a well working wheel that someone else made is the best choice.
- royka118 10y agoI did a bit of investigation into angular2 dependancies. It has alot more than angular1 and react http://royka.github.io/2016/05/03/front-end-deps.html http://royka.github.io/2016/05/03/front-end-deps.html
- paradite 10y agoInteresting fact that I recently came across: bower and many other npm packages, has some dependencies that eventually depends on a package called "wordwrap". And this "wordwrap" package somehow has its test folder exposed in npm. The result: Every single person using bower would have one or more copies of In Praise of Idleness by Bertrand Russell on your local machine, depending on how many of your projects has a npm dependency of this package: https://github.com/substack/node-wordwrap/blob/master/test/idleness.txt https://github.com/substack/node-wordwrap/blob/master/test/i... Don't believe me? Try searching for "In Praise of Idleness" in Spotlight. Edit: Someone had already sent a PR about this on GitHub: https://github.com/substack/node-wordwrap/pull/14 https://github.com/substack/node-wordwrap/pull/14
- heydenberk 10y agoI have 16 copies on my work computer.
- pandler 10y agoI have 94 copies.
- Arnt 10y agoThink of it as 94 NPM upvotes.
- marc_omorain 10y agoI have 8 copies.
- percept 10y agoWasteful yet subversive
- jabberlope 10y agoI don't know about you but I think the world can spare an extra 29kb.
- inaccessible 10y agoReminds me of this talk that I just watched: https://www.youtube.com/watch?v=k56wra39lwA https://www.youtube.com/watch?v=k56wra39lwA
- currywurst 10y agoIs there a "distribution" bundle convention for npm ? Analogous to static linking, it would be one .js file that would bind all dependencies into a bundle (e.g. gulp.dist.js) . In that case you would end up with a much smaller number of dependency files to manage.
- Klathmon 10y agoThere is for your final output (meaning the stuff you would upload to the server and serve to the user). but not for the development. IMO it's a pretty big anti-pattern to do that. It just hides the problem of managing dependencies (see, it's not 10,000 files, it's just one!), but doesn't fix any of the issues associated with it. Keeping each dependency small, and having tons of them means that deduplication can work better, tree shaking works better, and it lets you do things like swapping out one package for another with the same API.
- currywurst 10y agoIn this case, most of the files pulled down are the development dependencies which are not going to be exposed to the production code. I would be perfectly fine if npm pulled down "distribution" versions for tools like gulp, typescript et al
- Klathmon 10y agoIt might just be me living in a bubble, but I'd much rather have the full version downloaded to my machine in it's "raw" form than a "compiled" version. Even just for the ability to dive into the source i'm using if i'm debugging something, or be able to look at the actual code i'm running if I want to understand how a tool works. This is one of the reasons why I like how lodash handles their library. You can install the "regular" version of lodash and require it like "normal", or you can install a single big compiled lodash file, or you can install one that exports as ES6 modules, or you can install a single function at a time... Obviously every package can't afford to spend that much time on packaging, but a framework similar to that along with some changes to NPM to allow tagging a package as an "alias" of another (so lodash-as-one-big-file will be treated as lodash for other packages) would go a long way into making everyone happy.
- keeganjw 10y agoI started working with Laravel not long ago and found my project folder had 24,000+ files in it. And those don't compile down before you deploy... it makes me feel like I'm working on the tip of an unstable iceberg. Who the hell knows what's going on down there. No one person could possibly hope to know what it all actually does.
- jbverschoor 10y agoWhy isn't npm managing packages like ruby gems? SHARED_DIR/npm_modules/NAME/VERSION
- Klathmon 10y agoBecause package-lookup and the package manager are 2 completely separate systems in javascript. When you `require` or `import` a file in node.js, it looks for a node_modules and looks for that name in there. If it can't find it there, it starts walking up the directory tree until it finds something it can use (to a point). This is hardcoded and will be extremely difficult to change without a crazy amount of breaking. The package manager is free to install however, but it needs to put things where the package-lookup can find them.
- smrtinsert 10y agoEveryone knows it shouldn't be. Even a naive attempt by the average developer to write a package management system would take versions into account.
- Klathmon 10y agoAgain, it's not the package management system that is the problem, it's the module loader in node.js. And it's easy to say "even a naive attempt by the average developer" would do it better, but I really don't think they would have. Still, the fact is that this is what we have, and complaining about what could have been isn't going to do anyone any good, improving the system will.
- sah2ed 10y agoBut it is still possible to have the best of both worlds. Essentially, all they need to do is: 1. leave the current behavior for backwards compatibility; then 2. provide a flag like npm -G that exposes the correct behavior as suggested in the grand parent of using the same path like SHARED_DIR/node_modules/NAME/VERSION for package imports and package management. With time, newer npm versions will default to the correct behavior. For folks that need backwards compatibility, this would require explicitly setting a npm --compat flag or similar.
- moderndeveloper 10y agobabel 6 with jsx transformer used to install a comparable number of files due to module duplication. At one point it was a 100M install with some modules being duplicated 45 times. Much of this was the fault of npm 2. But with latest babel and npm 3 it's now a 35M install with 5700 files over 814 directories. I guess that's considered lean by modern standards.
- moderndeveloper 10y agoI've switch from babel 6 to buble recently. buble runs three times faster and its install size is 4.6M with 212 files over 39 directories. The install of buble is literally just "npm install buble" and it runs out of the box without configuration. Competition is a good thing.
- maaaats 10y agoJust because of the way npm2 ordered the dependencies, the runtime of babel got incredibly slow [1]. Npm3 fixed that drastically, but I wonder how much is still wasted just because of navigating the file tree to the dependencies. [1]: https://github.com/babel/babelify/issues/206 https://github.com/babel/babelify/issues/206
- STRML 10y agoThe opposite is true - directory traversals themselves are effectively free, this is not going to be something that slows down your app - but loading the JS & creating the IR will be much slower. The 4 second startup time with npm2 & babel6 is almost certainly due to the duplicated dependencies, which means literally hundreds of megs of JS have to be parsed & warmed up. With npm3, the same files are (correctly) reused which significantly speeds up start time.
- andrewclunn 10y agoOkay, but when you run the build process, how big is the resulting distributable?
- talmand 10y agoMy results of the hello world tutorial in Angular2 was 53 requests, 4933.49KB, and loaded in 1.74s on local dev, according to browser dev tools. All for one html file that had one h1 element. Plus, it started out broken. I had to search elsewhere to find the solution to the error the tutorial produced.
- aredherring 10y agoThat's not a production build. Minify it, run dead code elimination. Exactly as you would with any other language with a compiler. Also, worth noting that the tutorial being broken isn't symptomatic of JS, that's a problem with Angular (which has a history of sucking, and IMO Angular 2 just takes all of the problems with Angular 1 and adds more baggage to it). Be aware as well that Angular 2 is a full-fledged Web Framework. Even after all of this compression and such, it is not going to be as lightweight as you'd expect simply due to the nature of what you've installed. If you want something really lightweight, go with Rivets or React.
- talmand 10y agoI'm confused by your response. I haven't claimed anything along the lines of your response nor am I implying anything about Angular nor JS. I simply just communicated my results from completing the tutorial.
- kuschku 10y agoI thought I’d never use Rails as example for a lightweight web framework, but Rails has to be the standard – and anything heavier than rails has to be completely discarded.
- fernandopj 10y agoAt first glance, I thought the title was "Huge NO: on files for Angular 2" - a vulnerability report on filesystem capabilities of Angular 2 and why it should be abandoned