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.
yarn add webpack --dev yarn add ts-loader --devAfter 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
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.
Most helpful comment
Can you run
yarn run envcheck 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=productionit silently uninstalls all other devDependencies which seems mad.