logo hsb.horse
← Back to blog index

Blog

Settings to Run Yarn v4 (PnP Mode) in Bitbucket Pipelines

How to build a project that uses Yarn v4 in PnP mode on Bitbucket Pipelines. A quick summary of cache settings and how to enable corepack.

Published:

Yarn v4 in PnP (Plug’n’Play) mode is a newer package management style that does not use node_modules.

This is a short summary of how to configure Bitbucket Pipelines for building a Yarn v4 project.

Prepare the project

Create the project with Yarn v4.

Terminal window
yarn create vite yarn-v4-app --template vanilla-ts

Move into the directory.

Terminal window
cd ./yarn-v4-app && pwd

Bitbucket Pipelines configuration

Create bitbucket-pipelines.yml.

image: node:22.6.0
definitions:
caches:
yarn:
key:
files:
- yarn.lock
- .pnp.cjs
- .pnp.loader.mjs
path: ~/.yarn/berry/cache
scripts:
- &Init export TZ=Asia/Tokyo && corepack enable
- &Install yarn install --frozen-lockfile
pipelines:
custom:
build-vite:
- step:
name: "Build"
caches:
- yarn
script:
- *Init
- *Install
- yarn build

Points

  1. Enable corepack: use corepack enable so Yarn v4 becomes available
  2. Cache settings: manage the cache with yarn.lock, .pnp.cjs, and .pnp.loader.mjs as keys
  3. frozen-lockfile: use yarn install --frozen-lockfile to prevent lockfile changes

Summary

To run Yarn v4 in PnP mode on Bitbucket Pipelines, you need corepack enabled and the right cache settings.

Including the PnP files, .pnp.cjs and .pnp.loader.mjs, in the cache key helps keep builds efficient.