1

我对 Yarn Workspaces 感到困惑。我遵循了本教程:https://medium.com/trabe/monorepo-setup-with-lerna-and-yarn-workspaces-5d747d7c0e91但在其中一个子项目中,我仍然将包添加到 node_modules 中,这些包是从根节点模块。完整的测试仓库在这里:https ://github.com/donker/Dnn.React.Test

根包.json:

{
"name": "dnn-react-test",
"version": "1.0.0",
"description": "DNN React Component Library",
"license": "MIT",
"repository": {
  "type": "git",
  "url": "https://github.com/dnnsoftware/Dnn.React.Common.git"
},
"scripts": {
},
"private": true,
"workspaces": [
  "packages/*"
],
"devDependencies": {
  "lerna": "2.11.0"
}
}

子项目包.json:

{
  "name": "dnn-tooltip",
  "version": "0.2.5",
  "description": "Display an icon and associated tooltip showing a message from an array parameter",
  "main": "index.js",
  "scripts": {
  },
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/dnnsoftware/Dnn.React.Common"
  },
  "dependencies": {
    "lodash": "4.17.10",
    "react-portal-tooltip": "2.4.0",
    "dnn-global-styles": "^0.0.5"
  }
}

结果:packages/Tooltip/node_modules/lodash 创建。

预期:工具提示使用根文件夹中的 node_modules/lodash。

4

1 回答 1

1

让 lerna 和 yarn 正常工作需要在 lerna.json 中添加以下两个键值对:

"npmClient": "yarn",
"useWorkspaces": true

尽管这与您的问题没有直接关系,但我也建议更改

"workspaces": [
    "packages/*"
],

"workspaces": [
    "packages/**"
],

让 lerna 拾取子文件夹中的包(如 /packages/components/button)。

于 2018-11-06T19:31:50.163 回答