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 add in workspace adds to dependencies when it should update devDependencies #4971

Closed
greysteil opened this issue Nov 21, 2017 · 10 comments · May be fixed by #6943
Closed

yarn add in workspace adds to dependencies when it should update devDependencies #4971

greysteil opened this issue Nov 21, 2017 · 10 comments · May be fixed by #6943
Assignees
Labels
cat-bug fixed-in-modern This issue has been fixed / implemented in Yarn 2+. good first issue triaged

Comments

@greysteil
Copy link
Contributor

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

What is the current behavior?
Changing directory into a workspace and using yarn add nock adds nock to the dependencies for the package.json, rather than updating the version in devDependencies. Different versions of nock are then present within the same package.json in the dependencies and devDependencies.

I've created a repo so you can easily replicate, with a PR showing the erroneous result, here.

What is the expected behavior?
Yarn should update the devDependencies version of nock, like it would have done were we not in a workspace.

Please mention your node.js, yarn and operating system version.
Node: v8.9.1
Yarn: v1.3.2
OS: macOS 10.12.6

@ghost ghost assigned kaylie-alexa Nov 21, 2017
@ghost ghost added the triaged label Nov 21, 2017
@greysteil greysteil changed the title yarn add in workspace adds to dependencies if added package is in devDependencies yarn add in workspace adds to dependencies when it should update devDependencies Nov 21, 2017
@kaylie-alexa
Copy link
Member

@greysteil I believe that's the correct behavior, since you should use yarn upgrade nock if you want to update the existing dependency. Have you given that a go?

@greysteil
Copy link
Contributor Author

greysteil commented Nov 21, 2017

So cd packages/package1 && yarn add nock is supposed to have a different effect on my package.json if I'm using workspaces than if I'm not? That seems really unintuitive and surely not deliberate.

yarn upgrade nock doesn't update the contents of my package.json, so doesn't do an update. (Check out the PR I linked for details of the buggy result of yarn add nock - in particular, check out the duplicate appearance of nock. Surely that's not the desired behaviour?)

@kaylie-alexa
Copy link
Member

Sorry for the delay! So I was able to verify this bug on my end. yarn workspace package1 [add/upgrade] nock only seems to work on upgrading dependencies, and not devDependencies.

@rajeshshou
Copy link

yarn workspace package1 add dependency --dev adds to devDependencies

@pronebird
Copy link

pronebird commented Aug 9, 2018

I can confirm that upgrading devDependencies with yarn workspace does not work on yarn 1.9.2.

yarn workspace package1 upgrade dependency --latest

@scottseeker
Copy link

--dev is not working for me, it just adds to dependencies

@yshrsmz
Copy link

yshrsmz commented Apr 18, 2020

In my case, if I tried to install packages available at npm registry, it successfully adds to devDependencies.
But when I tried with local packages, it goes to dependencies regardless of -D or --dev.

@dmahendrakar
Copy link

dmahendrakar commented Aug 11, 2020

@greysteil @kaylie-alexa below commands adds to devDependencies for me -
yarn workspace <workspace> add <dependency> -D/--dev

Node: v12.16.3
Yarn: v1.22.4
OS: macOS 10.14.6

@JamesSingleton
Copy link

So it looks like adding a local package that has the bug mentioned here #4878 will add it to the dependencies instead of devDependencies... yarn workspace <workspace> add <local package dependency>@version -D/--dev

Node: 12.18.5
Yarn: 1.22.5
OS: macOS 10.15.6

@paul-soporan
Copy link
Member

Closing as this has been fixed in the v2.

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

@paul-soporan paul-soporan added the fixed-in-modern This issue has been fixed / implemented in Yarn 2+. label Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat-bug fixed-in-modern This issue has been fixed / implemented in Yarn 2+. good first issue triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants