Packed vs Unpacked: Estimating What Your Package Weighs
There are two numbers people mean by "package size", and they answer different questions. The packed size is the compressed tarball a registry stores and a client downloads. The unpacked size is what lands on disk in node_modules or site-packages. Neither is the bundle size a browser user pays for. This page shows how to estimate both and what each one is good for.
Reading the numbers npm already gives you
Running npm pack --dry-run in a package directory prints the file list that would be published, followed by a summary. The two lines that matter look like this (values illustrative):
npm notice package size: 18.4 kB
npm notice unpacked size: 71.2 kB
npm notice total files: 23
"Package size" is the gzipped tarball. "Unpacked size" is the sum of the file sizes inside it. For Python, build the distributions with python -m build and look at the wheel and sdist in dist/; a wheel is a zip archive, so its file size is the packed figure and the total of its extracted contents is the unpacked one.
The estimate, step by step
If you want to predict the size before building, or explain to a reviewer why it jumped, break the unpacked size into its parts:
unpacked ≈ runtime_code + type_declarations + source_maps + docs_and_meta + stray_files
packed ≈ unpacked × compression_ratio
Text such as JavaScript and Markdown compresses well with gzip, so the ratio for a code-only package is often well under one half. Already compressed assets (images, fonts, wasm) barely shrink. Treat the ratio as something you measure once on your own package, not a constant.
Worked example (illustrative)
| Component | Assumed size | Needed at install? |
|---|---|---|
| ESM and CJS builds | 40 kB | Yes |
| Type declarations | 8 kB | Yes, for TypeScript users |
| Source maps | 22 kB | Debatable |
| README, LICENSE, CHANGELOG | 12 kB | LICENSE yes; others optional |
| Test fixtures picked up by mistake | 310 kB | No |
The total unpacked estimate is 392 kB, and almost four fifths of it is fixtures nobody needs. Adding a files allow-list to package.json removes them:
{
"files": ["dist", "types", "LICENSE"]
}
npm always includes package.json, the README and the licence file regardless of this list, so you do not need to name them. Python projects get the same effect by checking what the build backend includes in the sdist and excluding fixtures in its configuration.
What these numbers do not tell you
- Dependency weight. Your own tarball can be tiny while your dependencies pull in megabytes. The install footprint is the sum across the whole resolved tree.
- Bundle cost. A bundler that tree-shakes your ESM build may ship only a fraction of the unpacked code to browsers; see measuring bundle size for that side.
- Install time. File count often matters more than bytes for install speed on slow disks, which is why the method in the install time benchmark notes is separate.
For more ways to slim a package once you know where the weight sits, read the tips on reducing install size.