Yarn removes previous packages when new one is added

Do you want to request a feature or report a bug?

What is the current behavior?
After installing certain packages as dev dependencies, multiple packages/files in the node_modules folder are missing. If the packages are not installed with “–dev” all appears to be OK.

If the current behavior is a bug, please provide the steps to reproduce.

  1. start with no node-modules folder, no yarn.lock and a vanilla package.json.
  2. yarn add webpack --dev
  3. yarn add ts-loader --dev

After step 3, node_modules no longer contains a large number ofpackages installed with webpack, and node_modules/.bin is missing the webpack executables that were present after step 2.

Example video : http://screencast-o-matic.com/watch/cbjeoblgpq

What is the expected behavior?
node_modules should contain still webpack etc…

Please mention your node.js, yarn and operating system version.
Windows 10 Pro
Yarn 0.28.4 (same with 0.27.5)
Node 8.2.1

Author: Fantashit

2 thoughts on “Yarn removes previous packages when new one is added

  1. Can you run yarn run env check the value of NODE_ENV ?

    I think if it’s “production”, you’ll get this problem. Try setting it to “development”. (For me it wasn’t immediately clear how to do this, because NODE_ENV didn’t show up at all when I ran SET from cmd prompt. But you can do it using SETX.

    It seems that if you install any package when you have NODE_ENV=production it silently uninstalls all other devDependencies which seems mad.

  2. I’ve had NODE_ENV correctly set for a while now and it seems definitely to fix the problem. The behaviour of yarn removing any devDependencies from node_modules in production appears as designed.

    I think if NODE_ENV=="production" then yarn install foobar --dev should throw an error. Currently it installs the package you request but quite probably uninstalls a bunch of others.

Comments are closed.