强制纱线将某些模块安装到给定的工作区,而不是将它们移动到 monorepo 的共享 node_modules?

Force yarn to install certain modules to given workspace, rather than moving them to shared node_modules of monorepo?

我有一个 monorepo(通过 yarn workspaces). One of the workspaces is a React app created via Create React App(我认为这很重要,因为 CRA 将 Webpack/Babel 放在它自己的 node_modules 中)。另一个工作区是纯 JavaScript 自带一套 Webpack + Babel 工具包。

我的问题是,当我从纯 JavaScript 工作区启动构建时,我得到这些:

然而,当我将工作区分离到一个独立目录(使用 copy/paste)并从那里构建时,它构建得非常好。

所以我猜是 monorepo 本身有问题。我还注意到指定的工作空间在本地 node_modules 中缺少 @babelbabel-runtimeregenerator-runtime,所以我从 monorepo 的主 node_modules 中 copy/pasted 它们文件夹,然后整个东西都建好了。现在这显然是 yarn monorepo 和 Webpack + Babel junction 架构中的一些缺陷。

是否可以强制 yarn 将特定模块安装到本地 node_modules,而不是 "helping me out",方法是将它们移动到根目录中的共享 node_modules单体仓库?

您可以使用nohoist。这将指示应在本地为软件包安装哪些模块。