1
votes

I'm confused about Yarn Workspaces. I've followed this tutorial: https://medium.com/trabe/monorepo-setup-with-lerna-and-yarn-workspaces-5d747d7c0e91 but in one of the sub projects I still get packages added to node_modules which are duplicated from the root node_modules. Full test repo is here: https://github.com/donker/Dnn.React.Test

Root package.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"
}
}

Subproject package.json:

{
  "name": "dnn-tooltip",
  "version": "0.2.5",
  "description": "Display an icon and associated tooltip showing a message from an array parametter",
  "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"
  }
}

Result: packages/Tooltip/node_modules/lodash created.

Expected: Tooltip uses node_modules/lodash from the root folder.

1

1 Answers

1
votes

Getting lerna and yarn to properly work together requires adding the following two key value pairs to your lerna.json:

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

Although this does not directly relate to your question, I would also suggest changing

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

to

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

to make lerna pick up packages in subfolders (like /packages/components/button).