Jea*_*eri 17 monorepo yarnpkg yarn-workspaces
在我的 Monorepo 里面,我有一个包,我想要它的 node_modules 中的所有依赖项。
但无论我做什么,它的 node_modules 仍然是空的。
因此,出于我的问题的目的,我能够通过以下设置重现该问题
/
package.json
lerna.json
node_modules
packages/
A/
node_modules
package.json
index.ts
B/
node_modules
package.json
index.ts
Run Code Online (Sandbox Code Playgroud)
我为此创建了一个回购!
主包.json
{
"name": "A-B-test",
"private": true,
"workspaces": {
"packages": ["packages/*"],
"nohoist": [ "**/B" ]
},
...
"devDependencies": {
"lerna": "^3.13.4"
}
}
Run Code Online (Sandbox Code Playgroud)
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"
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我yarn在项目的根目录中运行时,所有依赖项都安装在根目录中node_modules。
纱线版本:1.16.0 节点:12.4.0
任何建议可能是什么问题?
Era*_*mus 23
根据我的经验,有必要以下列方式双重指定每个包:
{
"nohoist": [
"**/B",
"**/B/**",
"**/C",
"**/C/**"
]
}
Run Code Online (Sandbox Code Playgroud)
另外,我发现有必要node_modules在修改nohoist设置后删除所有现有文件夹。因此,如果您的项目在 中packages,并且您在项目目录中,则可以node_modules像这样删除所有这些文件夹:
# delete node_modules on linux
rm -rf ./packages/*/node_modules
rm -rf ./node_modules
# install again
yarn install --check-files
Run Code Online (Sandbox Code Playgroud)
小智 21
我尝试了一些选项,但最终对我有用的唯一一个是nohoist在子包中指定选项。无需在根级别指定任何内容。
所以我的package.json包B是:
{
...
"workspaces": {
"nohoist": ["**"]
},
...
}
Run Code Online (Sandbox Code Playgroud)
将 nohoist 应用于子包的 package.json 对我来说是这样。
"workspaces": {
"nohoist": [
"*react-native*",
"*react-native*/**"
]
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9862 次 |
| 最近记录: |