marekpw
marekpw

Reputation: 712

Yarn installing multiple versions of the same package

I have angular in my dependencies at 1.5.11:

{
    "dependencies": {
        "angular": "1.5.11",
        "angular-foundation": "0.7.0"
    }
}

angular-foundation happens to depend on angular@>=1.3.0.

Why does Yarn install [email protected] as a nested dependency of angular-foundation instead of using the project's version? This causes angular to exist twice in the app and doesn't work properly:

node_modules angular (1.5.11) angular-foundation (0.7.0) node_modules angular (1.6.9)

This doesn't happen with [email protected] - npm uses 1.5.11 for both the app and the package.

Upvotes: 24

Views: 26445

Answers (2)

iugo
iugo

Reputation: 515

https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias

yarn add <alias-package>@npm:<package>

yarn add react17@npm:react@17

Upvotes: 25

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

You need to use Yarn resolutions for this

https://yarnpkg.com/lang/en/docs/selective-version-resolutions/

So your package.json will become like this

{
  "name": "depdencies",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",

    "dependencies": {
        "angular": "1.5.11",
        "angular-foundation": "0.7.0"
    },
    "resolutions": {
      "**/angular": "1.5.11"
    }
}

Which tells yarn that any child angular dependency will be set to 1.5.11. After updating this run below

$ rm yarn.lock
$ yarn

Upvotes: 27

Related Questions