CLI tool
pastelsky/bundlephobia avatar
pastelsky/bundlephobia

Bundlephobia: Measuring the Real Cost of an npm Dependency Before You Add It

🏋 Find out the cost of adding a new frontend dependency to your project

9,587 stars271 forksTypeScriptMIT

At a glance

What is it?
Bundlephobia answers a specific question: how much will this npm package add to my JavaScript bundle? This review covers how it works, how to run it, and where its approach falls short.
Who is it for?
Adopt Bundlephobia if you are a frontend developer who wants a quick, data-driven check before adding a dependency, or if you maintain a package and want to see how your own bundle size trends over time. Skip it if you need precise, production-accurate numbers or if you work with packages that have messy dependency declarations, because those will fail with MissingDependencyError or BuildError.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

The Problem Bundlephobia Solves

Every frontend developer has added a package, only to watch the bundle size jump. The cost is not just the package's own code. It includes its dependencies, the way it is bundled, and how it affects parsing and execution time. Bundlephobia exists to answer one question before you commit: what is the minified and gzipped size of this package, and how has that changed over time? The README states it plainly: 'Know the performance impact of including an npm package in your app's bundle.' This is for engineers who care about page load time and who want to compare two similar libraries without building a test project. It is also for package maintainers who want to see how their own releases affect consumers. The tool does not claim to measure runtime performance. It measures bytes, which is a proxy that is useful but not complete.

How Bundlephobia Computes Its Numbers

The core mechanism is not just reading the package.json and summing file sizes. Bundlephobia actually builds the package, the way a bundler would. It resolves the entry point, follows imports, and includes only what is reachable. This is why it can report a meaningful size for an ES6 package, as the README lists 'Works with ES6 packages' as a feature. The tool also supports CSS and SCSS packages, though that is marked as beta. The build process is where errors come from. If a package requires a dependency that is not listed in its own package.json or peerDependencies, Bundlephobia cannot resolve it and throws a MissingDependencyError. The README explains this: 'In the absence of such a definition, we cannot reliably report the size of the package.' This is a strictness that many size calculators do not have. It forces packages to declare their dependencies properly, which is good for accuracy but bad for packages that rely on hoisting or implicit resolution.

Getting Bundlephobia Running

The simplest way to use Bundlephobia is to visit bundlephobia.com and type a package name. The README points there first. But you can also run it yourself. The repository is a Node.js project with TypeScript as the primary language. To get it running locally, you would clone the repository, install dependencies with npm install, and then start the development server. The exact commands are not in the README excerpt, but the standard flow for a Node project applies: npm install, then npm run dev or npm start, depending on the scripts in package.json. The README also mentions a command line client, bundlephobia-cli, which is a separate project that wraps the API. For a quick check without setting up a server, that CLI is the practical route. The API itself is not documented in the README excerpt, but the existence of third-party integrations, such as the Atom plugin importcost and the browser extension that adds sizes to GitHub and npm pages, confirms that there is a public API behind the site.

Historical Trends and Package Composition

Two features stand out in the README: 'Reports historical trends' and 'See package composition.' Historical trends mean you can see whether a package has been growing or shrinking across releases. That is useful when a maintainer adds a dependency that looks small in isolation but has a long tail. The composition view breaks down the total size into individual files or modules, so you can see which part of a package is responsible for the bulk. This is the difference between knowing a package is 50 kB and knowing that 40 kB comes from a single utility that you could replace with your own five-line function. The README does not specify the exact format of the composition view, but the feature is clearly aimed at helping you make a decision, not just admire a number. This is where Bundlephobia moves beyond a simple size lookup and becomes a debugging tool.

Failure Modes and When It Is the Wrong Tool

Bundlephobia has a clear failure mode. If a package has an undeclared dependency, you get a MissingDependencyError and no size at all. That is a hard stop. The README suggests opening an issue with the package author, which is not a quick fix. Another failure is the BuildError, which happens when the package cannot be built at all. The README says you can look at the stack trace in devtools and open an issue, but there is no automatic workaround. This means Bundlephobia is the wrong tool for packages that are poorly maintained or that use unconventional build steps. It is also the wrong tool if you need a size for a package that is not on npm, or if you want to compare two versions of a package that are not published. The tool is also not designed for monorepos or for packages that are bundled with complex configurations. If you are evaluating a package that has a webpack loader or a custom plugin, the build may fail or give a misleading number.

Alternatives and How They Differ

The most direct alternative is to run your own bundler and measure the output. For example, you can create a minimal webpack or Rollup config, import the package, and check the output file size. That gives you a number that is specific to your setup, including your transpilation and minification choices. Bundlephobia uses a generic build, so it may not match your production configuration. Another alternative is the bundlephobia-cli, which is a wrapper around the same API, so it is not a different approach. A more different approach is to use a tool like webpack-bundle-analyzer, which shows you the composition of your own bundle after you have already added the dependency. That is retrospective, not prospective. The key difference is that Bundlephobia gives you a number before you install anything, while a bundle analyzer tells you the cost after you have committed. If you need a pre-install check, Bundlephobia is the only one that does it without a setup. If you need accuracy, you have to build it yourself.

Maintenance, License, and the Cost of Trusting It

The repository has not had a push since October 2019. The last release was v1.2.1 from September 2019. That means the code is stable, but it has not kept up with changes in npm, in Node.js, or in bundling practices. The README itself has a banner asking for contributors and co-maintainers, which is a sign that the original maintainer is not actively developing it. The license is MIT, so you can fork it and adapt it, but you would be taking on the maintenance burden. The API and the website still work, as of the material, but you should verify that the numbers are still current. The historical trend feature depends on the service having a database of past versions, and if the service is not updated, that database may be stale. For a one-off check, this is fine. For a permanent part of your CI pipeline, you would need to run your own instance and keep it updated, which is a real cost. The README does not mention any official support for self-hosting, but the repository is public and the license allows it.

Editorial conclusion

Adopt Bundlephobia if you are a frontend developer who wants a quick, data-driven check before adding a dependency, or if you maintain a package and want to see how your own bundle size trends over time. Skip it if you need precise, production-accurate numbers or if you work with packages that have messy dependency declarations, because those will fail with MissingDependencyError or BuildError. Before trusting a number, verify that the package's dependencies are correctly listed in its package.json, and check the historical trend section to see if the size has been stable. The project has not had a push since October 2019, so treat it as a stable but unmaintained tool, not something that will keep up with changes in the npm ecosystem.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Community notes

Community notes