Zero‑Installs with Yarn Berry: Caching Dependencies Inside the Repo for Instant Project Setup

User avatar placeholder
Written by Tamzid Ahmed

October 30, 2026

Getting a new clone of a JavaScript repo up and running traditionally takes minutes—if not longer—because the package manager must download every dependency from the internet. Zero‑Installs with Yarn Berry eliminates that friction by committing a fully‑populated cache to the repository, turning a fresh checkout into an instantly usable workspace.

What Is a Zero‑Install and Why It Matters

A zero‑install is a workflow where developers do not run yarn install after cloning a project. All modules are already present in the .yarn folder, which is version‑controlled. The benefits are immediate:

  • Lightning‑fast onboarding: New contributors can start coding within seconds.
  • Deterministic builds: The exact same artifact versions travel with the repo, preventing “works on my machine” bugs.
  • Offline CI: Continuous‑integration runners can skip network calls, reducing flaky builds.

Prerequisites: Yarn Berry (v2+) and a Git‑Ready Repo

Zero‑installs require Yarn Berry (also known as Yarn 2) because the classic Yarn (v1) stores caches outside the repository. Make sure you have:

  1. Yarn version 2 or later (`yarn -v` should show `2.x` or `3.x`).
  2. A Git repository with a clean .gitignore that does **not** ignore the .yarn folder.
  3. Node.js >=14 (the version you target in production).

Step‑by‑Step: Enabling Zero‑Installs

Follow these exact commands to turn any Yarn Berry project into a zero‑install repo.

  1. Initialize Yarn Berry (if you haven’t already):
    yarn set version berry
  2. Configure the cache location to live inside the repo:
    yarn config set cacheFolder .yarn/cache
  3. Enable zero‑install mode by telling Yarn to store the lockfile and the entire cache in the repository:
    yarn config set enableMirror true
  4. Commit the .yarn folder (including .yarn/cache and .yarn/releases) and the .yarnrc.yml file:
    git add .yarn .yarnrc.yml
    git commit -m "Enable zero‑install workflow"
  5. Verify locally: Delete node_modules if it exists, then run yarn install --check-cache. Yarn should report nothing to do because the cache already satisfies the lockfile.

At this point, any teammate who runs git clone followed by yarn install will see no network traffic; Yarn simply links the cached packages.

Optimising the Cache for Size and Security

While committing the entire cache guarantees zero‑install, large monorepos can bloat the repository. Consider these strategies:

  • Selective caching: Use the nodeLinker: node-modules setting for packages that rarely change; Yarn will fallback to a normal node_modules folder for volatile dependencies.
  • Archive the cache: Store the cache as a compressed artifact in the CI pipeline (e.g., GitHub Actions cache) and reference it with yarn install --immutable.
  • Security scan: Run yarn audit on the committed cache regularly to catch vulnerable packages before they reach developers.

Integrating Zero‑Installs into CI/CD

CI runners can reap the same time savings by reusing the repo‑bundled cache. A typical GitHub Actions step looks like this:

steps:
  - uses: actions/checkout@v3
  - name: Set up Node
    uses: actions/setup-node@v3
    with:
      node-version: '18'
  - name: Install dependencies (zero‑install)
    run: |
      yarn install --immutable --check-cache
  - name: Run tests
    run: yarn test

The --immutable flag forces Yarn to fail if the lockfile and cache are out of sync, guaranteeing reproducible builds.

Trade‑offs: When Zero‑Installs May Not Be Ideal

Zero‑installs shine for internal tooling and small‑to‑medium teams, but they have limits:

  • Repository size: Large caches can push repo size beyond 100 MB, hitting host limits.
  • Frequent dependency updates: Each version bump requires committing a new cache, which can increase PR size.
  • Cross‑platform binaries: Packages with native binaries need separate caches per OS, complicating monorepo handling.

If any of these concerns outweigh the benefits, consider a hybrid approach: keep core dependencies zero‑installed and let less‑stable ones install on demand.

Best Practices for Long‑Term Maintenance

To keep your zero‑install workflow healthy, embed these habits into your development cycle:

  1. Run yarn dedupe before committing to remove duplicate versions.
  2. Schedule a weekly yarn up run on a dedicated “maintenance” branch, then merge the refreshed cache.
  3. Document the zero‑install policy in your README.md with a clear Do not delete .yarn warning.

Conclusion

Zero‑installs with Yarn Berry turn a potentially sluggish yarn install into a seamless, offline operation by caching every dependency inside the repository. By configuring .yarnrc.yml, committing the .yarn folder, and adopting CI flags like --immutable, teams achieve instant project setup, deterministic builds, and reduced network reliance. Start with the step‑by‑step guide above, monitor repo size, and iterate the strategy to fit your workflow for maximum productivity.

Leave a Comment