Installs a package and any packages that it depends on.
Adding dependencies #
When you want to use another package, you first need to add it to your
dependencies. This means running yarn add [package-name] to install it into
This will also update your package.json and your yarn.lock so that other
developers working on the project will get the same dependencies as you when
they run yarn or yarn install .
Most packages will be installed from the npm registry
and referred to by simply their package name. For example, yarn add react
will install the react package from
the npm registry.
You can specify versions using one of these:
yarn add package-name installs the “latest” version of the package.
yarn add email@example.com installs a specific version of a package from
yarn add package-name@tag installs a specific
“tag” (e.g. beta , next , or latest ).
In general, a package is simply a folder with code and a package.json file
that describes the contents. You can refer to a package a number of different
You can also specify packages from different locations:
yarn add package-name installs the package from the
npm registry unless you have specified another one
in your package.json .
yarn add file:/path/to/local/folder installs a package that is on your
local file system. This is useful to test out other packages of yours that
haven’t been published to the registry.
yarn add file:/path/to/local/tarball.tgz installs a package from a gzipped
tarball which could be used to share a package before publishing it.
yarn add https://my-project.org/package.tgz installs a package from a
remote gzipped tarball.