不使用工作区的 Yarn nohoist

Z0q*_*Z0q 6 javascript hoisting apollo react-native yarnpkg

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

"workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/tslib",
      "**/tslib/**"
    ]
}
Run Code Online (Sandbox Code Playgroud)

现在,我不使用工作区,但由于我在 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).
Run Code Online (Sandbox Code Playgroud)

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

Thi*_*ijs 0

通过在您的文件中添加工作区配置,package.json您就可以使用工作区了。这就是为什么您收到有关将依赖项添加到工作区根目录的警告的原因。nohoist是仅限工作空间的选项;它的创建是为了使与纱线工作空间提升方案不兼容的第三方库仍然可以在工作空间下使用。参见https://classic.yarnpkg.com/blog/2018/02/15/nohoist/

\n
\n

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

\n
\n

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

\n