Yarn: Install a single package from devDependencies when yarn.lock exists?

Created on 9 Jan 2018  路  3Comments  路  Source: yarnpkg/yarn

I have a package.json that declares a X dependencies and Y devDependencies. I want to all the dependencies and only several of the the devDependencies (using the version which is locked inside yarn.lock). Considering I have the following package and lock:
https://gist.github.com/anonymous/78a6a2d2ff68c5a28640e9f6381a1652

I would expect that yarn add mocha would install ONLY mocha with the version specified in the lock file. In reality, running this command install ALL of my dependencies & devDependencies.
This doesn't sound like the correct behavior but I might be wrong, is there a way to achieve that type of behavior?

What I would ideally want to do is:

$ yarn install --frozen-lockfile --non-interactive --prod # install dependencies

$ yarn add mocha # install only a single dev dependency using the version from the lock
triaged

Most helpful comment

This is an incredibly annoying issue for me. We work with docker so we don't want any of our packages installed locally (that just leads to confusion) since they are all in our docker container. However I need our specific version of babel-eslint installed on my machine so my linting works in Atom or VSCode.

Is there seriously no way to ONLY install the version of babel-eslint that is already determined in yarn.lock? The dependency is already determined, it doesn't need to calculate the whole tree.

Update: So NPM supports only installing one package, and Yarn doesn't...so I used NPM. This seems kind of silly considering they are both doing the exact same thing.

All 3 comments

To be able to install a deterministic tree, Yarn needs to calculate the whole tree even if you change a single dependency so this is the expected behavior and cannot really change.

Moreover, when you run yarn add mocha, you tell Yarn to add mocha as a regular dependency (not dev) and to install its latest version since you don't define a version range.

If your working directory is missing some dependencies that are defined in your lock file, simply running yarn would make yarn install them.

In my situation, I need tsc to build. I have added typescript into dev deps, and when building I just want to add only typescriptdev deps and all production deps. Running yarn will install all dev deps.
How should I do to just install typescript dep which is already in yarn.lock?

This is an incredibly annoying issue for me. We work with docker so we don't want any of our packages installed locally (that just leads to confusion) since they are all in our docker container. However I need our specific version of babel-eslint installed on my machine so my linting works in Atom or VSCode.

Is there seriously no way to ONLY install the version of babel-eslint that is already determined in yarn.lock? The dependency is already determined, it doesn't need to calculate the whole tree.

Update: So NPM supports only installing one package, and Yarn doesn't...so I used NPM. This seems kind of silly considering they are both doing the exact same thing.

Was this page helpful?
0 / 5 - 0 ratings