javascript - 不使用工作区的 yarn nohoist

标签 javascript react-native apollo yarnpkg hoisting

我的一个项目突然无法在 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).
在我看来,这似乎不是最好的方法。我应该怎么办?

最佳答案

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

“nohoist” enables workspaces to consume 3rd-party libraries not yet compatible with its hoisting scheme. The idea is to disable the selected modules from being hoisted to the project root. They were placed in the actual (child) project instead, just like in a standalone, non-workspaces, project.


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

关于javascript - 不使用工作区的 yarn nohoist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69840040/

相关文章:

javascript - 整数/十进制用户输入 : how to serialize/store the value

javascript - 三个js对象3D旋转

javascript - 如何防止测试被汇总捆绑?

javascript - Three.js OBJ MTL 加载器在环境光下不起作用

javascript - javascript中静态方法的名称不能重复?

android - React Native Android 应用程序在收到推送通知时崩溃

ios - 如何在 React Native 上进行选择?

apollo 服务器 RDS 和 aws lambda

javascript - Apollo useQuery Hook 无法使用 writeQuery() 方法从缓存获取更新。没有看到错误

javascript - 文件模块 - node.js