【问题标题】:I installed Yarn and now create-react-app initially installs 879 dependencies我安装了 Yarn,现在 create-react-app 最初安装了 879 个依赖项
【发布时间】:2017-06-17 17:36:28
【问题描述】:

我了解了 Yarn 并想用 React 尝试它,所以我安装了 Yarn,现在当我运行 create-react-app hello 时,其中一个脚本似乎是 yarn add v0.24.6,它将 879 个依赖项安装到我的 node_modules 目录中。

为什么会发生这种情况,我该如何阻止它?还是我只是不了解 Yarn 而这应该是我想要的东西?

【问题讨论】:

    标签: reactjs create-react-app yarnpkg


    【解决方案1】:

    你以前用过 npm2 吗?有了它,您只会在node_modules 中看到您的应用程序的直接依赖项,而它们的 依赖项(即您的应用程序的传递依赖项)将隐藏在嵌套的node_modules 目录中。

    Yarn 和 npm >= 3 个扁平化依赖项在 node_modules 中,因此您会看到所有 react-scripts 的直接依赖项它的所有传递依赖项。

    【讨论】:

    • 知道了。只是没有意识到 create-react-app 有那么多依赖项
    【解决方案2】:

    我们使用的每个包都可能依赖于其他包。

    yarnnpm > 3 使用平面结构来解决其他包依赖关系的依赖关系。所以,你的 node_modules 文件夹容器长的文件夹列表。

    npm < 3 使用nested tree 结构。因此,您的 node_modules 文件夹容器包含几个文件夹列表以及嵌套在 package/node_modules 文件夹中的其他包的依赖项。

    那么,为什么要使用npm > 3 or yarn

    这些可以快速解决依赖关系。我希望你还没有在npm install :D 之后等待 1 小时或更长时间的经验。

    为什么要在 npm 上使用纱线?

    有很多关于这个主题的文章。谷歌一下就行了。

    【讨论】:

    • 感谢您的意见。现在更有意义了。
    猜你喜欢
    • 2020-01-19
    • 2017-12-05
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多