Yarn: dev dependencies keep disappearing

Created on 16 Mar 2017  路  7Comments  路  Source: yarnpkg/yarn

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

Bug

What is the current behavior?

Whenever I add a new package or run yarn install, all my dev dependencies disappear from my node_modules directory.

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

I've experienced this issue in multiple projects, but here is just one case.

When I run yarn install, it appears my dev dependencies don't get installed and in fact get removed if they are already installed.

Whether I run yarn install or add a new dependency, all my dev dependencies are removed. The only way to install them is to add them in one command ex: yarn add webpack babel-core etc... -D Then even after I do that, if I add a new module (for example: yarn add immutable), all my dev dependencies are once again removed from my node_modules directory.

Here is my package.json:

{
  "name": "nebo-client",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --hot --inline --progress --colors",
    "build": "webpack",
    "storybook": "start-storybook -p 9001 -c .storybook"
  },
  "author": "Jacob Wisniewski",
  "license": "ISC",
  "dependencies": {
    "apollo-client": "^0.10.1",
    "axios": "^0.15.3",
    "chart.js": "^2.4.0",
    "d3": "^4.7.3",
    "date-fns": "^1.28.0",
    "fecha": "^2.3.0",
    "graphql-tag": "^1.3.1",
    "hex-rgba": "^1.0.0",
    "immutable": "^3.8.1",
    "lodash": "^4.17.4",
    "moment": "^2.17.1",
    "normalizr": "^3.2.2",
    "react": "^15.4.2",
    "react-apollo": "^0.13.2",
    "react-dom": "^15.4.2",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.1",
    "react-router-redux": "^4.0.7",
    "redux": "^3.6.0",
    "redux-thunk": "^2.1.0",
    "styled-components": "^1.3.0",
    "typeface-clear-sans": "0.0.20"
  },
  "devDependencies": {
    "@kadira/storybook": "^2.35.3",
    "babel-cli": "^6.24.0",
    "babel-core": "^6.24.0",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.4.0",
    "babel-plugin-transform-async-to-generator": "^6.22.0",
    "babel-preset-env": "^1.2.2",
    "babel-preset-latest": "^6.24.0",
    "babel-preset-react": "^6.23.0",
    "babel-preset-react-hmre": "^1.1.1",
    "css-loader": "^0.27.3",
    "eslint": "^3.17.1",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-loader": "^1.6.3",
    "eslint-plugin-flowtype": "^2.30.3",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.0",
    "extract-text-webpack-plugin": "^2.1.0",
    "file-loader": "^0.10.1",
    "flow-bin": "^0.41.0",
    "html-loader": "^0.4.5",
    "html-webpack-plugin": "^2.28.0",
    "react-hot-loader": "^1.3.1",
    "redux-devtools": "^3.3.2",
    "storybook-host": "^1.0.14",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.4.2"
  }
}

What is the expected behavior?

That my dependencies don't disappear. 馃槢

Please mention your node.js, yarn and operating system version.

Yarn: v0.21.3
Node: v7.6.0
OS: osx 10.12.3

triaged

All 7 comments

I have a similar issue (not sure if they are the same or even related). However, in my case, it's a single dependency that disappears after being added correctly.

This dependency is defined using file path like so: "common": "file:../common". I tried to reproduce in another project copying just the various packages.json into same directory structure, but was not able to do so.

Both real project and repro have the same enty in yarn.lock for my dependency. Maybe a caching issue somwhere.

Strange.

Have the same issue here!

Also happens on yarn remove

Wow, that was really weird. Had a similar problem, but with slightly-different reproduction steps.

Summary

Make sure process.env.NODE_ENV is not production. And perhaps it's production because your terminal is a child process of a Node application that has NODE_ENV set to production.

Diagnosis of my case

  • Windows.
  • yarn install was not installing & removing dev dependencies.
  • Was running from a terminal inside atom.
  • In the project's directory and from atom's terminal, running node and printing process.env.NODE_ENV seems to be production (unexpectedly. I didn't set it to that).
  • Running from a normal commandline (cmd, in Windows), process.env.NODE_ENV is undefined as expected.

Problem source of my case

Atom is, to my understanding, a Node application/process. Its NODE_ENV is production. The terminal is a child process that inherits the environment. When node is started inside it, it inherits the environment as well.

Workaround of my case

  • Just run yarn install --production-false or run from the cmd.

Stuff I'm unable to explain

  • It was working correctly before. The last thing I remember before it starts failing is running npm upgrade -g yarn (which did nothing, #3042) and adding a package.
  • platformio-atom-ide-terminal seems to omit NODE_ENV, but I don't know why it's not working. Didn't really dive into the code.

References

@hossameldeen: I didn't know that yarn install --production=false works. So, that overrides the behavior caused by the NODE_ENV environment variable being set to production, is it?

@amarnus, seems so #2167. But it's not documented yet. Sent a PR yarnpkg/website#510.

I found this same issue happening where certain dependencies would disappear.

Because yarn has been having trouble installing Electron due to the package download (checksum error every time), I ended up leaving Electron out of the package.json to use the global npm install. The problem was that my NpmInstallPlugin for Webpack would see it was missing from the local node_modules, and try to install Electron while also removing dependencies with npm causing it to break every time I ran it.

Most likely this is not the issue of others, but I would think this is definitely an edge-case to keep in mind, especially knowing that cross-installing with npm can cause this to happen.

This doesn't seem to be a bug in Yarn so closing.

Was this page helpful?
0 / 5 - 0 ratings