Skip to content

Yarn

Created: 2018-04-23 17:14:22 -0700 Modified: 2018-12-03 15:13:22 -0800

  • Installing on Debian: just check this link (reference).
  • “yarn why pkgname” - figure out _why a particular package is installed (e.g. it’s a dependency of a dependency)
  • To check if a package is even downloadable, you can do “yarn info package_name”.
  • To set the registry for scoped packages: npm config set @botland:registry =URL
    • You need to log in to that specific registry afterward: npm adduser —registry=URL
  • The registry for Yarn should be left as https://registry.yarnpkg.com
    • You probably shouldn’t modify NPM to point at that. It sounds like pretty good advice to just never modify the default registries for package managers.
  • CLI documentation availablehere.
  • npm initis nowyarn init.
  • yarnwithout argument will executeyarn install.
  • yarn install —prodto force a production installation without dev dependencies (will do the same whenNODE_ENVis set to production wich will be the case when deploying).
  • To add a dependency, useyarn add <package[@version_or_tag]>(package can be a package name from the NPM registry, a local file path, a local gzipped tarball, a git remote repository or a remote gzipped tarball).
  • To add a different kind of dependency, add an option like—dev/-Dfor a dev dependency (or—peer/-P,—optional/-O,—exact/-E&—tilde /-T).
  • Remove a package withyarn remove <package>.
  • Run a script withyarn [run] <script>. You can append any argument directly, no need for the—madness.
  • yarn runalone will list all available scripts.
  • To upgrade packages interactively, useyarn upgrade-interactive(This command respect the version range in package.json, to ignore it pass the—latestextra argument).
  • To upgrade a package to a specific version / tag, useyarn upgrade <package>,yarn upgrade <package@version>oryarn upgrade <package@tag>(Note that without a version or tag, it’ll upgrade the module to the latest version based on the version range specified in the package.json file.).
  • To upgrade all packages to their latest version based on the version range defined inpackage.jsonwhich is the old equivalent ofrm -rf node_modules && npm install, you can useyarn upgrade
  • To checkwhya package is installed, useyarn why <package>.
  • To list outdated packages, useyarn outdated.
  • To list all packages, useyarn ls.
  • To clear the local cache, useyarn cache clean.

From <https://github.com/Adam13531/bot-land/pull/55>

If you ever find yourself wanting to fork a GitHub repo solely so that you can update a version/link in their package.json (e.g. because the maintainer hasn’t done so already), you would use this feature.

HiDeoo used this in this pull request to Bot Land. He included this note:

If you decide to use more selective version resolution as it is an amazing and very easy to use tool, just know that with a monorepo using Yarn Workspaces, even if the package is not hoisted, you should always pin the version in the root package.json file instead of the nested one where the dependency might be use.

Yarn is using the right registry, but “npm adduser” didn’t seem to take

Section titled Yarn is using the right registry, but “npm adduser” didn’t seem to take

Try “always-auth”:

npm config set always-auth true

I think this is necessary now for Verdaccio whereas it wasn’t for Sinopia. HiDeoo suggests using this everywhere regardless of problems / custom registries.

Yarn changes https:// to http:// for some packages in the lockfile

Section titled Yarn changes https:// to http:// for some packages in the lockfile

https://github.com/yarnpkg/yarn/issues/6259