Yarn
lastmod 2024-11-04created 2018-09-0221 edits
Yarn caches every package it downloads so it never needs to download it again. It also parallelizes operations to maximize resource utilization so install times are faster than ever.
Categories
- Berry (yarn2; yarn-berry; Yarn Berry)
- Npm:Link -
npm link- mainly useful for library development. - GitLabCI:Yarn
Command
To initialize when starting a project (creates package.json):
To install dependency modules from package.json:
To install a dependency module (same as npm install --save):
For reference, a global install (same as npm install -g):
To add dependencies of other categories such as devDependencies, peerDependencies, and optionalDependencies:
To upgrade a dependency module:
To remove a dependency module:
List installed packages:
Run an executable from an installed module.
Comparing v1 and v2 commands
| Yarn Classic (1.x) | Yarn (2.x) | Notes |
| | | |
| | | </code>yarn create</code> still works, but prefer using |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | Will now upgrade packages across all workspaces |
| | | Requires the workspace-tools plugin |
| | <code>YARN_ENABLE_INLINE_BUILDS=true yarn install |
yarn.lock
Because the package.json file downloads packages according to Semantic versioning rules, the versions downloaded can change over time. So a yarn.lock file is created that stores the versions of installed modules, so that dependencies have the same versions and structure everywhere.
In other words, this file must not be added to the.gitignore file.
yarn automatically creates yarn.lock on every yarn install. You can think of it as doing much the same as package-lock.json.
Publish
The command is the same as Npm#Publish. However, log in with npm first, referring to Npm#Login, and then publish.
How to use npx
Consider installing ynpx, or add the command to script in the package.json file.
Plugin
Troubleshooting
Extracting tar content of undefined failed
Do not build in the $HOME directory.
The engine "node" is incompatible with this module
[email protected]: The engine "node" is incompatible with this module. Expected version ">=18.17.0". Got "18.16.1"
Upgrade your Node.js version.
Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated
warning accept-language > [email protected]: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility