How to target a single workspace with Yarn?

Thijs Koerselman picture Thijs Koerselman · Jun 28, 2019 · Viewed 8.5k times · Source

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?

Answer

user123 picture user123 · Jun 28, 2019

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?