developer

Upgrading yarn from 1.x

I still have a lot of old projects using yarn 1.x and I need to record the instructions somewhere

Shaun Wilde
Yarn on spindles

I needed to update a project from yarn 1.x to the latest version (and maintain node modules) and though I have done this a number of times this year I always look up the instructions from the yarn website. Today I struggled to find them and then eventually realised that the instructions were on an older version of the yarn website (for 3.x) and that they were not included in the latest website (for 4.x).

So for my own sanity I am noting them here [Note this works for 1.22.19 to 4.0.2]

yarn set version berry    
yarn config set nodeLinker node-modules            
yarn install

Then a little testing and deduping doesn't go amiss here

yarn test
yarn dedupe
yarn test

Next, add the following to .gitignore

.yarn/*
!.yarn/releases

And finally, if possible, add it to renovate (updating according the node version) so that deduping happens on every package update "postUpdateOptions": ["yarnDedupeHighest"],

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": ["config:base"],
  "automerge": false,
  "labels": ["renovate"],
  "timezone": "Australia/Melbourne",
  "postUpdateOptions": ["yarnDedupeHighest"],
  "packageRules": [
    {
      "matchUpdateTypes": ["minor", "patch", "pin", "digest"],
      "matchPackagePatterns": ["*"],
      "automerge": true,
    },
    {
      "matchPackagePatterns": ["node"],
      "allowedVersions": "= 18"
    }
  ]
}

Once everything is stable and patched/upgraded then I look if it is possible to switch to yarn with PnP.

Photo by 🇸🇮 Janko Ferlič on Unsplash