npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

is-tree-shakable

v0.4.2

Published

![](https://img.shields.io/npm/v/is-tree-shakable)

Readme

is-tree-shakable

This is a command‍-‍line tree‍-‍shakability doctor for JavaScript packages. Compared to alternatives, it not only reports whether a package is tree‍-‍shakable but also pinpoints the root causes of non‍-‍tree‍-‍shakability in the JavaScript or TypeScript source.

Getting started

  1. Ensure that your package’s package.json file specifies "main", "module", or "browser".

  2. If your package is built, enable source‍-‍map generation. For TypeScript, this is done via "sourceMap".

Usage

  1. If your package is built, run the build step.

  2. Run is-tree-shakable in the package root:

    • base resolution:

      npx is-tree-shakable
    • web resolution (supports "browser" and .web.js):

      npx is-tree-shakable --resolution web

    If the package is tree‍-‍shakable, is-tree-shakable produces no output and exits with code 0; otherwise, it lists the root causes of non‍-‍tree‍-‍shakability and exits with code 1.

Background

Tree shaking is a technique used by modern JavaScript builds tools‍—‍such as Webpack, Rollup, or Parcel‍—‍to remove unused code during bundling, saving space and boosting performance. It’s particularly beneficial for package consumers, who often use only a subset of the exported members. While tree shaking occurs in the consumer’s build pipeline, a package must meet two criteria to enable the removal of its unconsumed code. When this is the case, the package is tree‍-‍shakable.

  1. It must use ES6 modules.

  2. It must be obviously free of externally observable side effects that occur during module evaluation.

While the adoption of ES6 modules is straightforward, the second requirement presents a significant pitfall. Some logic‍—‍like modifying window at the module level‍—‍is evidently problematic. However, because the static analysis that powers tree shaking in widely used bundlers is quite simplistic, they err on the side of caution and also treat many verifiably side effect‍–‍free constructs as side‍-‍effectful. As a result, code that could be safely eliminated is unexpectedly retained.

is-tree-shakable helps avoid this: it pinpoints constructs that block tree shaking, whether they truly have externally observable side effects or merely are treated as such by bundlers. Collectively, these are referred to as possibly side-effectful.

Addressing non-tree-shakability

When is-tree-shakable flags a construct as possibly side-effectful, evaluate if it actually has externally observable side effects. If so, move it accordingly. If not, use @__PURE__, which is a standard annotation that bundlers treat as a guarantee of non‍-‍side‍-‍effectfulness.

  • For call expressions, usage is straightforward:

    /* @__PURE__ */ foo();
  • Other constructs‍—‍such as property access‍—‍may also be reported as possibly side effectful, but @__PURE__ is applicable only to call expressions. To work around this, use an IIFE:

    /* @__PURE__ */ (() => bar.baz)();

Suppression

If a construct that blocks tree shaking needs to be preserved, you can silence is-tree-shakable for that specific statement with the is-tree-shakable-suppress directive:

/* is-tree-shakable-suppress */ foo();

By Software Mansion

Founded in 2012, Software Mansion is a software agency with experience in building web and mobile apps. We are core React Native contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product‍—‍hire us.