Hossam El-Deen
Hossam El-Deen

Reputation: 1112

How can I fix the yarn error 'Unknown workspace'?

Problem

Running yarn workspace <nohoisted-package> start gives error Unknown workspace "twitter-digester-frontend".

Details

Root package.json

{
  "name": "x",
  "private": true,
  "version": "1.0.0",
  "workspaces": {
    "packages": ["x-backend"],
    "nohoist": ["x-frontend"]
  },
  "scripts": {
    "backend": "yarn workspace x-backend",
    "frontend": "yarn workspace x-frontend"
  }
}

Command

Question

Why does yarn workspace fail with nohoisted packages?

I don't fully understand nohoist. I'm mainly using it because Angular CLI in x-frontend couldn't read node_modules when not using nohoist. I'm assuming it only means don't symlink packages - that's why I see no reason yarn workspace <nohoisted-package> <script> shouldn't work.

Upvotes: 6

Views: 7910

Answers (1)

The first thing your root package.json should contain an array of your workspaces:

{
...
 "workspaces": [
    "example",
    "my-pkg-js"
  ]
}

The second thing to check is when you run yarn workspace <workspace> start the <workspace> stands for the name in your package.json in your package directory. For example:

yarn workspace package-name start

The name property in my-pkg-js/package.json file should be something like:

{
...
 "name": "package-name"
}

Upvotes: 16

Related Questions