Yarn: Yarn removes previous packages when new one is added

Created on 3 Aug 2017  路  6Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
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

Most helpful comment

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.

All 6 comments

Using --verbose, I see the the modules get removed by yarn as extraneous.

Lots of this:-

verbose 3.935 Removing extraneous file "C:\\Rascular\\Products\\wcdev\\node_modules\\timers-browserify".
verbose 3.939 Removing extraneous file "C:\\Rascular\\Products\\wcdev\\node_modules\\to-arraybuffer".
verbose 3.943 Removing extraneous file "C:\\Rascular\\Products\\wcdev\\node_modules\\tty-browserify".
verbose 3.946 Removing extraneous file "C:\\Rascular\\Products\\wcdev\\node_modules\\uglify-js".
verbose 3.963 Removing extraneous file "C:\\Rascular\\Products\\wcdev\\node_modules\\uglify-to-browserify".
verbose 3.966 Removing extraneous file "C:\\Rascular\\Products\\wcdev\\node_modules\\uglifyjs-webpack-plugin".

I see, it's removing some extraneous files, similarly when you use npm prune. Any idea to prevent this happening? I did some browsing and try those solutions, but no luck

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.

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.

Ohhh, previously I set NODE_ENV to production which led me to this chaos.
Now I set the NODE_ENV to development, and the problems are gone. Thanks :)

Opened an issue to discuss this further: https://github.com/yarnpkg/yarn/issues/4095

Closing this one for the sake of that other, more focused issue.

Was this page helpful?
0 / 5 - 0 ratings