首页 > 解决方案 > 不使用工作区的纱线 nohoist

问题描述

我的一个项目突然无法在 Windows 笔记本电脑上编译,而完全相同的代码在 Mac 上运行。我已经阅读了关于提升和添加 nohoist 的信息,这似乎解决了 Apollo 客户端的问题。

"workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/tslib",
      "**/tslib/**"
    ]
}

现在,我不使用工作区,但由于我在 package.json 中使用上面的代码,Yarn-W在添加或删除包时询问参数:

error Running this command will add the dependency to the workspace root rather than
the workspace itself, which might not be what you want - if you really meant it, make it
explicit by running this command again with the -W flag (or --ignore-workspace-root-check).

在我看来,这似乎不是最好的方法。我应该怎么办?

标签: javascriptreact-nativeapolloyarnpkghoisting

解决方案


通过在您的中添加工作区配置,您package.json已启用工作区的使用。这就是您收到有关将依赖项添加到工作区根目录的警告的原因。nohoist是一个工作区唯一的选项;创建它是为了使与 yarn 工作区提升方案不兼容的 3rd 方库仍可在工作区下使用。见https://classic.yarnpkg.com/blog/2018/02/15/nohoist/

“nohoist” 使工作空间能够使用尚未与其提升方案兼容的第 3 方库。这个想法是禁止选定的模块被提升到项目根目录。它们被放置在实际(子)项目中,就像在独立的非工作区项目中一样。

如果您不想使用工作区,则需要从您的工作区中删除工作区配置package.json并以另一种方式修复您的编译问题。


推荐阅读