Yohohodev

Using a specific version of Yarn in the project

#Yarn

To use a specific version of Yarn for your project, first, check the current version. You might already have the version you need:

yarn --version

Then run the following command in the terminal:

yarn set version 4.0.2

You can choose any available version of Yarn that you need. For example:

yarn set version 3.1.0

To use the most recent stable release instead of a specific version, run:

yarn set version stable

After that, you'll notice changes in the project files:

.yarn/
.yarnrc.yml
package.json

If you want to utilize Yarn PnP (Plug'n'Play) to optimize disk space, you need to enable Yarn PnP. Otherwise, proceed directly to the step of adding files to .gitignore. For more detailed information on this, you can read here.

  1. Open the .yarnrc.yml file and check for the presence of the nodeLinker field, which determines the strategy for installing node modules.
  2. If the field is not there or set to pnp, Yarn PnP is enabled.
  3. Otherwise, remove the field or change its value to pnp.

To ensure proper IDE and IntelliJ support for the TypeScript version used in the project, generate the corresponding settings.

If you are using VSCode:

  1. Install the ZipFS extension.
  2. Then, run
yarn dlx @yarnpkg/sdks vscode
  1. Set the TypeScript version to Use Workspace Version.

For other IDEs, follow the instructions provided.

Additionally, update your .gitignore to exclude unnecessary files and folders, preventing project clutter. For more details, check the official documentation.

If you're using Zero-Installs:

.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

If you're not using Zero-Installs:

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

Finally, install the project's node modules:

yarn install