yarnpkg/yarn · error · MessageError
workspacesRemoveRootCheck
Error message
workspacesRemoveRootCheck
What it means
When `yarn remove` is invoked in a workspace root (config.cwd === config.workspaceRootFolder), removing a dependency there would affect every workspace. As a guard, remove.js:39-40 throws workspacesRemoveRootCheck unless `--ignore-workspace-root-check` (-W) is passed.
Source
Thrown at src/cli/commands/remove.js:37
commander.description('Removes a package from your direct dependencies updating your package.json and yarn.lock.');
commander.usage('remove [packages ...] [flags]');
commander.option('-W, --ignore-workspace-root-check', 'required to run yarn remove inside a workspace root');
}
export function hasWrapper(commander: Object, args: Array<string>): boolean {
return true;
}
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
const isWorkspaceRoot = config.workspaceRootFolder && config.cwd === config.workspaceRootFolder;
if (!args.length) {
throw new MessageError(reporter.lang('tooFewArguments', 1));
}
// running "yarn remove something" in a workspace root is often a mistake
if (isWorkspaceRoot && !flags.ignoreWorkspaceRootCheck) {
throw new MessageError(reporter.lang('workspacesRemoveRootCheck'));
}
const totalSteps = args.length + 1;
let step = 0;
// load manifests
const lockfile = await Lockfile.fromDirectory(config.lockfileFolder);
const rootManifests = await config.getRootManifests();
const manifests = [];
for (const name of args) {
reporter.step(++step, totalSteps, `Removing module ${name}`, emoji.get('wastebasket'));
let found = false;
for (const registryName of Object.keys(registries)) {
const registry = config.registries[registryName];
const object = rootManifests[registryName].object;View on GitHub (pinned to c2dda503f3)
Solutions
- Move into the specific workspace package directory and run `yarn remove <pkg>` there.
- If you truly intend to remove the dependency from the root workspace, pass `-W` / `--ignore-workspace-root-check`.
- Confirm your CWD with `pwd` and the workspace layout with `yarn workspaces info` before retrying.
Example fix
# before (in workspace root) $ yarn remove lodash # workspacesRemoveRootCheck # after $ cd packages/my-app && yarn remove lodash # or, intentionally at root $ yarn remove lodash -W
Defensive patterns
Strategy: validation
Validate before calling
const path = require('path');
function assertNotRootUnlessAllowed(config, flags) {
const isRoot = config.workspaceRootFolder && config.cwd === config.workspaceRootFolder;
if (isRoot && !flags.ignoreWorkspaceRootCheck) {
throw new Error('Refusing remove in workspace root; cd into a workspace or pass -W.');
}
} Try / catch
try {
await runYarn(['remove', pkg]);
} catch (e) {
if (/workspacesRemoveRootCheck/.test(e.message)) {
console.error('Run from a workspace package, or pass -W to remove at root.');
return;
}
throw e;
} Prevention
- Operate on dependencies from within the owning workspace directory.
- Only pass `-W` when you intentionally change root-level deps.
- Print CWD/workspace info in scripts to avoid accidental root operations.
When it happens
Trigger: Running `yarn remove <pkg>` while CWD is the workspace root, without the `-W` flag.
Common situations: Being parked in the monorepo root by default; tooling that shells out from the root; forgetting which workspace you're in.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/7afee7c4c9fbf360.
Report an issue: GitHub.