【问题标题】:Yarn installing multiple versions of the same package纱线安装同一个包的多个版本
【发布时间】:2018-08-10 21:23:43
【问题描述】:

我在 1.5.11 的依赖项中有 angular

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

angular-foundation 恰好依赖于angular@>=1.3.0

为什么 Yarn 安装 angular@1.6.9 作为 angular-foundation 的嵌套依赖项而不是使用项目的版本?这会导致 Angular 在应用程序中存在两次并且无法正常工作:

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

npm@5.6.0 不会发生这种情况 - npm 对应用程序和包都使用 1.5.11。

【问题讨论】:

    标签: npm yarnpkg


    【解决方案1】:

    您需要为此使用Yarn 分辨率

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

    所以你的package.json会变成这个样子

    {
      "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"
        }
    }
    

    这告诉yarn 任何子角度依赖都将设置为1.5.11。在下面更新此运行后

    $ rm yarn.lock
    $ yarn
    

    【讨论】:

      【解决方案2】:

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

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

      yarn add react17@npm:react@17

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 2021-04-28
      相关资源
      最近更新 更多