Search code examples
npmyarnpkglernayarn-workspaces

Yarn - Workspaces - Lerna - I fail to use the workspaces feature to add my packages


I have this folder tree:

my_project_tree 
|
├── lerna.json
├── package.json
├── package-lock.json
├── packages
│   └── editor_implementation
│       ├── dist
│       ├── package.json
│       └── src
│          
├── yarn-error.log
└── yarn.lock

My editor_implementation/package.json has the following content:

{
  "name": "@my_project_tree/editor_implementation",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT"
}

my root folder my_project_tree/package.json has the following content:

{
  "name": "hocotext",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "workspaces": [
    "packages/*"
  ],
  "private": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "dotenv": "^6.0.0"
  },
  "devDependencies": {
    "lerna": "^3.4.0"
  }
}

My lerna.json at root level has the following content:

{
  "version": "patch",
  "command": {
    "publish": {
      "ignoreChanges": [
          "ignored-file",
          "node_modules",
          "*.md"
      ]
    },
    "bootstrap": {
      "ignore": "component-*",
      "npmClientArgs": ["--no-package-lock"]      
    }
  },
 "npmClient": "yarn",
 "useWorkspaces": true,
 "packages": ["packages/*"]
}

When I run from root:

  • yarn workspace packages/editor_implementation add °some packages°
  • yarn workspace packages/* add °some packages°
  • lerna add °some packages°

All commands fails with a message abstractable as :

Uknow package...

Package {} not found...

I can't figure out what is wrong since It seems to me I have following all the requirements, if someone has any hint, would be great.


Solution

  • In order to spot your workspaces, you simply have to run :

    yarn workspaces info
    

    In my case it returns:

    {
      "@hoco_editor/editor_implementation": {
        "location": "packages/editor_implementation",
        "workspaceDependencies": [],
        "mismatchedWorkspaceDependencies": []
      }
    }
    

    So I have run my commands with @hoco_editor/editor_implementation as following:

     yarn workspace @hoco_editor/editor_implementation add °some packages°
    

    And it works like a charm.