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 workspace doesn't respect uniqueness of peerDependencies #8113

Closed
gavrix opened this issue May 11, 2020 · 2 comments
Closed

Yarn workspace doesn't respect uniqueness of peerDependencies #8113

gavrix opened this issue May 11, 2020 · 2 comments
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.

Comments

@gavrix
Copy link

gavrix commented May 11, 2020

Bug description

Yarn seems to treat peerDependencies as regular dependencies when workspace mode. This happens for both hoisted and nohoisted modules.

In simplest workspaces setup with workspaces: ''alpha", "beta", "gamma", "delta"
master package.json

{
    "name": "yarn-demo",
    "private": true,
    "workspaces": {
        "packages": [            
            "alpha",
            "beta",
            "gamma",
            "delta"
        ]
    }
}

alpha:

{
    "name": "alpha",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "react": "~16.13.1",
        "react-native": "~0.61.5"
    }
}

beta:

{   
    "name": "beta",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "react": "16.13.1",
        "react-native": "0.61.5"
    }
}

gamma:

{
    "name": "gamma",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "react": "^16.13.1",
        "react-native": "^0.62.2",
        "react-native-svg": "^12.1.0"
    }
}

delta:

{
    "name": "delta",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "react": "16.13.1",
        "react-native": "0.61.5",
        "react-native-svg": "12.1.0"
    }    
}

Command

yarn install

What is the current behavior?
yarn install in this repo installs a copy of react-native inside react-native-svg:

➜  yarn-debug find ./ -regex '.*react-native/package.json'
.//beta/node_modules/react-native/package.json
.//delta/node_modules/react-native/package.json
.//delta/node_modules/react-native-svg/node_modules/react-native/package.json
.//gamma/node_modules/react-native/package.json
.//alpha/node_modules/react-native/package.json

What is the expected behavior?
react-native is a peer dependency of react-native-svg (with version match "*" — any version) and isn't supposed to be installed into react-native-svg/node_modules accorrding to https://classic.yarnpkg.com/en/docs/dependency-types/#toc-peerdependencies

Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package.

Environment

  • Node Version: v13.2.0
  • Yarn v1 Version: 1.22.4
  • OS and version: MacOS 10.15.4
@jayphelps
Copy link

Was just bit by this. Are you also using nohoist in your root package.json? If so, I believe it's a duplicate of #5520. As soon as I stopped using nohoist this problem went away for me; though the other problems I had that nohoist was avoiding came back of course.

@merceyz
Copy link
Member

merceyz commented Jan 2, 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+.
Projects
None yet
Development

No branches or pull requests

3 participants