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.
yarn create vite yarn-v4-app --template vanilla-tsMove into the directory.
cd ./yarn-v4-app && pwdBitbucket Pipelines configuration
Create bitbucket-pipelines.yml.
image: node:22.6.0definitions: 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 buildPoints
- Enable corepack: use
corepack enableso Yarn v4 becomes available - Cache settings: manage the cache with
yarn.lock,.pnp.cjs, and.pnp.loader.mjsas keys - frozen-lockfile: use
yarn install --frozen-lockfileto 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.
hsb.horse