30

I have workspaces set up like this

"private": true,
  "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/firebase-admin",
      "**/firebase-admin/**",
      "**/firebase-functions",
      "**/firebase-functions/**"
    ]
  },

In my packages dir I have a folder common amongst others, with its own package.json etc.

When I execute yarn workspaces run build it triggers the build script for all workspaces. However if I try to target one specific workspace with the yarn workspace command like yarn workspace common build I keep getting the error:

error Unknown workspace "common".

Here's my output from yarn workspaces info:

yarn workspaces v1.17.0
{
  "@gemini/cli": {
    "location": "packages/cli",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  },
  "@gemini/cloud-functions": {
    "location": "packages/cloud-functions",
    "workspaceDependencies": [
      "@gemini/common"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "@gemini/common": {
    "location": "packages/common",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  },
  "@gemini/tools": {
    "location": "packages/tools",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  }
}

I have tried changing the name to package/common or @gemini/common but without luck.

What am I missing here?

tk421
  • 5,775
  • 6
  • 23
  • 34
Thijs Koerselman
  • 21,680
  • 22
  • 74
  • 108

2 Answers2

48

When you want to call command on particular workspace you should use package name which is set in its package.json file "name". In your case it should be:

yarn workspace @gemini/common build

I have tried changing the name to package/common or @gemini/common but without luck.

You should not see error error Unknown workspace "@gemini/common". Maybe some other error you are getting?

user123
  • 1,053
  • 15
  • 27
  • 2
    I was sooo sure I had tried that ‍♂️I must have seen a different error when I did. But it works now, thanks! – Thijs Koerselman Jun 28 '19 at 20:59
  • why is this not working for install? I have exactly the same setup, yet it's installing node_modules everywhere. I just want to do it for dam project. – Red Baron Mar 19 '20 at 12:13
  • This doesn't seem to work well: `yarn workspace foo upgrade-interactive` for example offers upgrading packages in all workspaces, not just `foo`... Is there a way to restrict this to only that workspace? – P Varga Nov 06 '20 at 11:43
  • Short answer to your specific question - No. I would suggest to read more about dependency management with yarn V1 or create dedicated question about your problem – user123 Nov 06 '20 at 11:54
4

If you'd like to run a build script in workspace <workspace>, then the syntax for the command is

yarn workspace <workspace> build

E.g., I have the following in my root package.json:

  "workspaces": [
    "api",
    "app"
  ],

So then I can run yarn workspace api build.

dan
  • 1,144
  • 12
  • 17
  • 3
    All of my workspaces live in the packages subdirectory. I tried "packages/common" but that wasn't it. So apparently you have to use the module name. In your case it is the same as your workspace package directory name, but that's not what the command requires. – Thijs Koerselman Jun 28 '19 at 21:11