Docs/Intermediary concepts/Workspace profiles

Workspace profiles

Reuse configuration between your workspaces

When working with monorepos, you often find yourself repeating the same dev dependencies across multiple workspaces. Maybe all your TypeScript packages need @types/node, or all your React packages need @testing-library/react. Instead of duplicating these dependencies in every package.json, workspace profiles let you define reusable sets of dev dependencies that can be shared across workspaces.

Defining profiles#

Profiles are defined in your .yarnrc.yml file under the workspaceProfiles key. Each profile can contain dev dependencies and can extend other profiles:

workspaceProfiles:
  typescript:
    devDependencies:
      "@types/node": "^20.0.0"
      "typescript": "^5.0.0"

  react:
    devDependencies:
      "@testing-library/react": "^14.0.0"
      "react": "^18.0.0"

  fullstack:
    extends:
      - typescript
      - react
    devDependencies:
      "eslint": "^8.0.0"

Using profiles#

To apply a profile to a workspace, add an extends field to its package.json:

{
  "name": "my-package",
  "extends": ["typescript"]
}

You can extend multiple profiles, and they will all be merged together. The default profile is always automatically included, even if you don’t specify it explicitly.

Profile inheritance#

Profiles can extend other profiles, allowing you to build up complex configurations from simpler building blocks. When a profile extends another, all of its dev dependencies are inherited.

Precedence#

When the same dependency is defined in several places, the most specific definition wins. From the most to the least specific:

  1. The workspace’s own devDependencies.

  2. The profiles listed in the extends field of the workspace. When two of them define the dependency, the one listed last wins.

  3. The profiles those profiles extend, then the profiles these ones extend, and so on. A profile always wins over the profiles it extends, and what a profile inherits never wins over a profile the workspace lists itself, whatever the order. Between two profiles at the same distance from the workspace, the one listed last wins (and what it extends wins over what the other extends).

  4. The default profile, followed by the profiles it extends. It only provides what nothing else defines, even when it’s named in an extends list.

For instance, with the following configuration:

workspaceProfiles:
  default:
    devDependencies:
      "@yarnpkg/node": "builtin:^24.0.0"
      "typescript": "^5.0.0"

  legacy:
    devDependencies:
      "@yarnpkg/node": "builtin:^22.0.0"

A workspace declaring "extends": ["legacy"] uses Node.js 22 and TypeScript 5, and the other workspaces Node.js 24 and TypeScript 5. A workspace that lists @yarnpkg/node in its own devDependencies uses that version, whatever the profiles say.

Upgrading the dependencies of a profile#

yarn up treats the dependencies declared by the profiles of your .yarnrc.yml like those declared by your workspaces: the range of each profile entry matching the requested packages is updated in place, along with the package.json files that declare the same dependency. Whatever wraps the range of an entry (a patch, an alias) is kept, as it is in a manifest.

# Updates `typescript` in every profile and workspace that declares it
yarn up typescript

Limitations#

  • Profiles only apply to dev dependencies. Regular dependencies must still be declared in each workspace’s package.json.

  • If a workspace already declares a dev dependency in its package.json, profiles won’t override it. This ensures that workspace-specific requirements always take precedence over shared profiles.