yarnpkg/yarn · error · MessageError

installCommandRenamed

Error message

installCommandRenamed

What it means

Yarn 1 removed npm-style `install <pkg>` and its `--save*` family flags; adding packages is done exclusively via `yarn add`. This error (lang key installCommandRenamed, defaulted at install.js:1162) is thrown whenever positional package arguments are passed to `yarn install`, with the message suggesting the equivalent `yarn add` invocation. If --global is also set the key switches to globalFlagRemoved and points at `yarn global add`.

Source

Thrown at src/cli/commands/install.js:1192

    }
    if (flags.savePeer) {
      exampleArgs.push('--peer');
    }
    if (flags.saveOptional) {
      exampleArgs.push('--optional');
    }
    if (flags.saveExact) {
      exampleArgs.push('--exact');
    }
    if (flags.saveTilde) {
      exampleArgs.push('--tilde');
    }
    let command = 'add';
    if (flags.global) {
      error = 'globalFlagRemoved';
      command = 'global add';
    }
    throw new MessageError(reporter.lang(error, `yarn ${command} ${exampleArgs.join(' ')}`));
  }

  await install(config, reporter, flags, lockfile);
}

export async function wrapLifecycle(config: Config, flags: Object, factory: () => Promise<void>): Promise<void> {
  await config.executeLifecycleScript('preinstall');

  await factory();

  // npm behaviour, seems kinda funky but yay compatibility
  await config.executeLifecycleScript('install');
  await config.executeLifecycleScript('postinstall');

  if (!config.production) {
    if (!config.disablePrepublish) {
      await config.executeLifecycleScript('prepublish');
    }

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Replace `yarn install <pkg>` with `yarn add <pkg>`.
  2. For dev/peer/optional deps use `yarn add --dev|--peer|--optional <pkg>` (mirrored in exampleArgs at install.js:1172-1186).
  3. For global install use `yarn global add <pkg>`.
  4. If you genuinely meant to install from the lockfile, run `yarn install` with NO positional arguments.

Example fix

// before
$ yarn install lodash
// after
$ yarn add lodash
Defensive patterns

Strategy: validation

Validate before calling

// Before invoking yarn programmatically, ensure install is called with no positional package args
const installArgs = process.argv.slice(2);
const wantsAdd = installArgs.length > 0; // any positional pkg -> must use `add`
if (wantsAdd) {
  console.error('Use `yarn add <pkg>` instead of `yarn install <pkg>`');
  process.exit(1);
}

Try / catch

// If you shell out to yarn, detect this MessageError and surface the migration hint
try {
  await runYarn(['install', ...pkgs]);
} catch (e) {
  if (e && e.message && e.message.includes('installCommandRenamed')) {
    throw new Error('Migration needed: use `yarn add` for package installation.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `yarn install lodash`, `yarn install pkg1 pkg2`, or `yarn install pkg --save-dev` (any positional args cause args.length to be truthy at install.js:1169, bypassing the real install path and reaching the throw at :1192).

Common situations: npm users migrating to yarn running `yarn install <pkg>` out of habit; CI scripts that still pass package names to install; shell aliases that append args.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/75426640398cb55a. Report an issue: GitHub.