Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Get sizes of installed packages #10361

Closed
davej opened this issue Nov 12, 2015 · 11 comments
Closed

Get sizes of installed packages #10361

davej opened this issue Nov 12, 2015 · 11 comments

Comments

@davej
Copy link

davej commented Nov 12, 2015

With npm 2.x, I could do easily go into the node-modules folder and inspect a folder to find out the modules' size on disk. With npm 3 and flat deps this isn't possible (it's not that unusual for the node_modules dir of a large project to have 1,000+ directories).

This isn't a big problem for most node applications but when using something like Electron it's important to have a handle on the size of modules so that you can keep the final binary size as small as possible.

Possible API:

> npm size
└── standard@3.13.2     1.54MB
└── fix-path@1.1.0      2.34MB
└── mkdirp@0.5.1        0.43MB
└── node-uuid@1.4.3     1.11MB
> npm size --depth=1
└─┬ standard@3.13.2     1.54MB
│ ├── deglob@1.0.1      0.33MB
│ ├── dezalgo@1.0.3     0.82MB
│ └── ...               x.xxMB
└─┬ fix-path@1.1.0      2.31MB
  ├── ...               x.xxMB
  └── ...               x.xxMB
> npm size standard
└─┬ standard@4.5.4           1.54MB
  ├─┬ deglob@1.0.1           0.33MB
  │ ├─┬ glob@5.0.15          0.11MB
  │ │ ├─┬ inflight@1.0.4     0.04MB
  │ │ │ └── wrappy@1.0.1     0.03MB
  │ │ ├── inherits@2.0.1     0.07MB
@davej
Copy link
Author

davej commented Nov 12, 2015

Related to #4638, although the scope of this issue is larger.

Another thought on this... it would be best to right-align the module size. That would make it much easier to read and compare sizes. For example.

└── standard@3.13.2       1.54MB
└── fix-path@1.1.0      112.34MB

@kenany
Copy link
Contributor

kenany commented Nov 12, 2015

Well this is in the works: #9920

@davej
Copy link
Author

davej commented Nov 12, 2015

Thanks @kenany, after looking at #9920 it looks like npm ls --with-sizes is probably better than adding a new size sub-command. It looks like that PR only supports npm install though (not npm ls).

@mikermcneil
Copy link

I put together https://github.com/mikermcneil/kit#kit-deps as a stopgap for this in case it's helpful for anyone (cc @davej)

@mikermcneil
Copy link

(see also @siddharthkp's cost-of-modules! If you're interested in a rich, deliberate report rather than incidental estimation, his is way better than mine. Also, mine only works on NPM 2... so yeah. There's that.)

@siddharthkp
Copy link

@mikermcneil Thanks for the mention! ❤

@pastelsky
Copy link

pastelsky commented Apr 2, 2017

Also, if you're more interested in the size impact of a module post bundling and minifying, rather than its size on disk, I wrote a small online utility that can tell you that-
https://cost-of-modules.herokuapp.com (not related to @siddharthkp 's awesome package)

EDIT: It's now moved to https://bundlephobia.com

@blockscoped
Copy link

blockscoped commented May 4, 2017

Could you not just use du -sh node_modules or du -sh node_modules/<pkg-name> ?
Assume there's a Windows equivalent too.

@siddharthkp
Copy link

@blockspeed

From cost-of-modules readme:

With npm 2.x, it was easy to find how much space is each of your dependencies taking. You could just look at the size of each directory in node_modules

Exactly what you suggested. But,

With npm 3, the packages are installed in flat manner, so it isn't so straightforward.

You will not get the next level dependencies, because it's all flat.

@npm-robot
Copy link

We're closing this issue as it has gone thirty days without activity. In our experience if an issue has gone thirty days without any activity then it's unlikely to be addressed. In the case of bug reports, often the underlying issue will be addressed but finding related issues is quite difficult and often incomplete.

If this was a bug report and it is still relevant then we encourage you to open it again as a new issue. If this was a feature request then you should feel free to open it again, or even better open a PR.

For more information about our new issue aging policies and why we've instituted them please see our blog post.

@arve0
Copy link

arve0 commented Oct 14, 2017

For those interested, I've created npm-download-size which resolves dependencies and calculates size for tarballs without downloading any packages. The total size of all tarballs gives you a good estimate if a given package is bloated.

The cli tool can be used like this:

$ download-size request
request@2.83.0: 1.08 MiB

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants