【问题标题】:Yarn workspaces with Lerna still adding packages to subfolders带有 Lerna 的纱线工作区仍在将包添加到子文件夹
【发布时间】:2019-04-08 19:44:34
【问题描述】:

我对 Yarn Workspaces 感到困惑。我遵循了本教程:https://medium.com/trabe/monorepo-setup-with-lerna-and-yarn-workspaces-5d747d7c0e91,但在其中一个子项目中,我仍然将包添加到 node_modules,这些包从根 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。

【问题讨论】:

    标签: lerna yarn-workspaces


    【解决方案1】:

    要让 lerna 和 yarn 正常工作,需要将以下两个键值对添加到您的 lerna.json:

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-01
      • 2020-07-04
      • 2020-07-31
      • 2021-06-03
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      相关资源
      最近更新 更多