Using Yarn 4 in the Build Pipeline

In order to be able to use Yarn 4 to build your node projects, you will need to add the following commands to your build pipeline:

source /opt/nvm/nvm.sh
nvm install 18
nvm use 18

corepack enable
corepack prepare yarn@4.8.1 --activate
yarn --version

Note: DeployHQ build servers come with NVM (Node Version Manager) 0.40.3 pre-installed, so you can directly source it from /opt/nvm/nvm.sh without needing to install it first.

What's new in Yarn 4?

  • Enhanced Plug'n'Play (PnP): It heavily leverages PnP, reducing dependency size and speeding up installations.
  • Stronger Security: It includes features like "Hardened Mode" to protect against supply chain attacks.
  • Corepack Integration: It emphasizes Corepack for consistent package manager versions.
  • Improved Performance: It has performance optimizations, like a new package metadata cache.
  • Modernizing Yarn: Requires Node.js 18+ to leverage newer javaScript features.

Happy deploying!