SoFunction
Updated on 2025-03-11

Detailed explanation of how to use and upgrade yarn

Preface

There is a sentence in the official introduction:

Yarn is a package manager for your code. It allows you to use and share code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don't ever have to worry.

The key meaning is fast, safe and reliable. The package you download will no longer be downloaded again. And make sure it works properly in different systems.

Use of yarn

The yarn package management tool is a fast, reliable and secure dependency management tool on the official website. I tried it and it was quick to get it and it was quite convenient to use it. You can try it.

yarn installation

Install the following on the mac computer:

brew update

brew install yarn

yarn workflow

1. Create a new project

yarn init

Similar to npm init, configuration

2. Add dependencies

yarn add [package]

Similar tonpm install

3. Install dependencies

Install all dependencies:yarn oryarn install

Install a single version of a package:yarn install --flat

Force re-download all packages:yarn install --force

Install production environment dependencies only:yarn install --production

Comparison of commands between yarn and npm

For details, you can view:/zh-Hans/docs/migrating-from-npm

Introduction to yarn's cli command

For details, you can view:/zh-Hans/docs/cli/

yarn config set mirror

I've written it beforenpm domestic mirroring, solution for npm installation failure, we can also set up Taobao images through yarn's config. The relevant commands are as follows:

yarn config list

List paths

yarn config set registry /

Set up Taobao mirror.

New ways to upgrade

When I use

yarn add webpack

When you are asked:

error [email protected]: The engine "node" is incompatible with this module. Expected version ">=4.3.0 <5.0.0 || >=5.10".
error Found incompatible module

Say my nodejs version is too old. How to easily upgrade nodejs in mac? The method is as follows:

You can use npm or yarn to install n toolkits, the steps are as follows:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

In this way, nodejs will be upgraded to the latest stable version!

n is a Node toolkit that provides several upgrade command parameters:

nShow installed Node version

n latestInstall the latest version of Node

n stableInstall the latest stable version of Node

n ltsInstall the latest long-term maintenance version (lts)Node

n <version>Install Node according to the provided version number

Summarize

The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.