Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"yarn install --production" brings in dev dependency deps to node_modules #6323

Closed
albertstill opened this issue Aug 29, 2018 · 14 comments
Closed
Assignees
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+. triaged

Comments

@albertstill
Copy link

albertstill commented Aug 29, 2018

What is the current behaviour?
I run yarn install --production and it brings in react and react-dom to the top of node_modules even though react and react-dom is a dep of a dev dep. This is proved by yarn why below. I also manually checked all package.json's in node_modules folder (after prod install) to see if react/react-dom existed as dep, it did not. The issue does not occur with npm install --production. I also want to clarify this is not the same as #3630, these deps are actually wrongly appearing node_modules.

yarn why react

yarn why v1.9.4
[1/4] 🤔  Why do we have the module "react"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react@16.4.2"
info Reasons this module exists
   - "@domain-group#fe-build" depends on it
   - Hoisted from "@domain-group#fe-build#react"
info Disk size without dependencies: "52MB"
info Disk size with unique dependencies: "4.58GB"
info Disk size with transitive dependencies: "52MB"
info Number of shared dependencies: 9
✨  Done in 0.94s.
yarn why react-dom

yarn why v1.9.4
[1/4] 🤔  Why do we have the module "react-dom"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react-dom@16.4.2"
info Reasons this module exists
   - "@domain-group#fe-build" depends on it
   - Hoisted from "@domain-group#fe-build#react-dom"
info Disk size without dependencies: "132MB"
info Disk size with unique dependencies: "4.66GB"
info Disk size with transitive dependencies: "132MB"
info Number of shared dependencies: 9
yarn why @domain-group/fe-build

yarn why v1.9.4
[1/4] 🤔  Why do we have the module "@domain-group/fe-build"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@domain-group/fe-build@13.6.2"
info Has been hoisted to "@domain-group/fe-build"
info This module exists because it's specified in "devDependencies".
✨  Done in 1.07s.

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

Unfortunately we have private npm modules, so not entirely possible. Here is the yarn.lock and the repos package.json. I could provide private package.json's if this helps or any other suggestions.

What is the expected behavior?
react and react-dom will not appear in node_modules/react and node_modules/react-dom.

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

Latest of everything

macOS 10.13.3
yarn 1.9.4 (even happened in yarn nightly 1.10.0-20180828.1752)
node v8.11.4

@ghost ghost assigned rally25rs Aug 29, 2018
@ghost ghost added the triaged label Aug 29, 2018
@albertstill albertstill changed the title "yarn install --production" brings in a dev dependency dep "yarn install --production" brings in dev dependency deps Aug 29, 2018
@albertstill albertstill changed the title "yarn install --production" brings in dev dependency deps "yarn install --production" brings in dev dependency deps to node_modules Aug 29, 2018
@ajhool
Copy link

ajhool commented Aug 29, 2018

Can confirm, am having this same problem.

A similar issue was posted and resolved a while ago #3577

I'm using Workspaces and local file dependencies (Lerna uses local file dependencies under the hood, too).

@ajhool
Copy link

ajhool commented Aug 30, 2018

I'm not familiar with the inner-workings of yarn, but it seems that using the --production flag causes the yarn/package-linker.js to miss excludeDevDependencies for directDependency workspaces

Here are some various pieces of information about dir size and dependency inclusion:

moduleB depends on moduleA using a local file reference.
moduleC depends on moduleA using a local file reference
aws-sdk is a devDependency for moduleA, moduleB, and moduleC
nohoist should be enabled for all packages

yarn install [--production] is called from project root

moduleA/node_modules [seems correct]
  yarn install --production
    - 27 MB
    -  aws-sdk [ no - good ] 
  yarn install
    - 64 MB
    - aws-sdk [ yes - good ] 

moduleB/node_modules/moduleA/node_modules
  yarn install --production
    - 64 MB 
    - aws-sdk [ yes - bad ]
  yarn install
    - 27 MB
    - aws-sdk [ no - unsure ]

moduleC/node_modules/moduleA/node_modules 
  yarn install --production
    - 64 MB
    - aws-sdk [ yes - bad ]
  yarn install
    - 27 MB
    - aws-sdk [ no - unsure ]

moduleC/node_modules
  yarn install --production
    - 137 MB
    - aws-sdk [ no - good]
  yarn install
    - 137 MB
    - aws-sdk [ yes - good ]

Command to add moduleA to moduleB ( assume package name is moduleA and file path is also ./packages/moduleA).

cd moduleB
yarn add ./packages/moduleA
yarn add -D aws-sdk

@albertstill
Copy link
Author

thanks for further info @ajhool! We are not actually using workspaces or local file deps and still having this issue. It's causing multiple versions of React in our bundled code and breaking things.

@mattfysh
Copy link

Confirmed this is occurring with v1.13.0

@lili21
Copy link

lili21 commented Oct 23, 2019

any update?

@rebolyte
Copy link

Still happening with v1.21.1. ☹️

@EyMaddis
Copy link

What does the --production flag actually do then? I am a bit struck by my 2.5 GB production installations which include my build setup.

@justrustc
Copy link

Still happening with v1.21.1. ☹️

@StanleyDharan
Copy link

Is there any temporary solution to navigate this problem in the interim of a permanent solution?

@METACEO
Copy link

METACEO commented May 29, 2020

I hate to be the "+1" guy, but using 1.22.4 I was surprised to find my production build was over a gigabyte because my devDependencies were included in the production install. Has this been the same issue for over a year?

@rally25rs
Copy link
Contributor

I'd never really run yarn with --production because webpack makes my deployment bundles, but I noticed that if I yarn install then yarn install --production my dev dependencies are still in node_modules.
However if I rm -rf node_modules && yarn install --production then only my dependencies are in node_modules.
So it seems like maybe yarn just isn't clearing out the dev deps if they already exist in node_modules?
Maybe someone else can try deleting node_modules first before the install --production and see if they see the same behavior?

@METACEO
Copy link

METACEO commented May 29, 2020

Thanks @rally25rs - I've been running yarn install --production within new/fresh Docker containers. But I can try manually within the containers and see what I find.

@lpender
Copy link

lpender commented Jan 14, 2021

FWIW, this is still an issue.

NODE_ENV=production yarn install --production=true

^ totally installs all devDependencies

yarn -v
1.22.10

@merceyz
Copy link
Member

merceyz commented Jan 14, 2021

Closing as fixed in v2

https://yarnpkg.com/getting-started/migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+. triaged
Projects
None yet
Development

No branches or pull requests