工作区仍在吊装的 nohoist [英] nohoist with workspaces still hoisting
问题描述
在我的 Monorepo 中,我有一个包,我希望在其中包含 node_modules 中的所有依赖项.
Inside my Monorepo I have one packages in which I want all the dependencies inside its node_modules.
但无论我做什么,它的 node_modules 都是空的.
But whatever I do, it's node_modules remains empty.
因此,就我的问题而言,我能够通过以下设置重现该问题
So, for the purpose of my question I was able to reproduce the issue with the following setup
/
package.json
lerna.json
node_modules
packages/
A/
node_modules
package.json
index.ts
B/
node_modules
package.json
index.ts
我为此创建了一个repo!
主包.json
{
"name": "A-B-test",
"private": true,
"workspaces": {
"packages": ["packages/*"],
"nohoist": [ "**/B" ]
},
...
"devDependencies": {
"lerna": "^3.13.4"
}
}
B/package.json
看起来像
{
"name": "@scaljeri/B",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"angular": "^1.7.8"
},
"devDependencies": {
"browserify": "^16.2.3",
"typescript": "^3.5.2"
}
}
现在,当我在项目的根目录中运行 yarn
时,所有依赖项都安装在根目录 node_modules
中.
Now when I run yarn
in the root of the project, all dependencies are installed in the root node_modules
.
纱线版本:1.16.0节点:12.4.0
yarn version: 1.16.0 node: 12.4.0
任何建议可能是什么问题?
Any suggestions what might be the problem?
推荐答案
根据我的经验,有必要按照以下方式对每个包进行双重指定:
In my experience, it has been necessary to doubly specify each package in the following manner:
{
"nohoist": [
"**/B",
"**/B/**",
"**/C",
"**/C/**"
]
}
此外,我发现有必要在修改 nohoist
设置后删除所有现有的 node_modules
文件夹.因此,如果您的项目在 packages
中,并且您在项目目录中,则可以像这样删除所有这些 node_modules
文件夹:
In addition, I have found it necessary to delete all existing node_modules
folders after modifying the nohoist
settings. So, if your projects are in packages
, and you are in your project directory, you can delete all of those node_modules
folders like this:
# delete node_modules on linux
rm -rf ./packages/*/node_modules
rm -rf ./node_modules
# install again
yarn install --check-files
这篇关于工作区仍在吊装的 nohoist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!