Search code examples
yarnpkgmonorepo

add yarn workspace to other workspace as dependecy


I want to setup a yarn workspace monorepo structure to my project, below is the basic structure.

Main
   - packages
       - Auth
           - package.json
       - Site1
           - package.json
       - Site2
           - package.json
   - package.json
/* Main/package.json */
{
    "private": true,
    "name": "Main",
    "workspaces": ["./packages/*"]
}

I want to add the @Main/Auth packages dependency to @Main/Site1 and @Main/Site2. I have tried this

yarn workspace Site1 add Auth

It's giving the error: An unexpected error occurred: "https://registry.yarnpkg.com/@Main/Auth: Not found".

PS: I have just added @Main as a prefix to make this less common.


Solution

  • It appears from looking at the Yarn docs, you don't issue a yarn command or anything, you just manually build the package.json files by hand.

    So, inside Site/package.json you would put something like:

    {
      "name": "@Main/Site1",
      "version": "1.0.0",
      "private": true,
      "dependencies": {
        "@Main/Auth": "^1.0.0"
      }
    }