{"record":{"id":"75426640398cb55a","repo":"yarnpkg/yarn","slug":"installcommandrenamed","errorCode":null,"errorMessage":"installCommandRenamed","messagePattern":"installCommandRenamed","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/install.js","lineNumber":1192,"sourceCode":"    }\n    if (flags.savePeer) {\n      exampleArgs.push('--peer');\n    }\n    if (flags.saveOptional) {\n      exampleArgs.push('--optional');\n    }\n    if (flags.saveExact) {\n      exampleArgs.push('--exact');\n    }\n    if (flags.saveTilde) {\n      exampleArgs.push('--tilde');\n    }\n    let command = 'add';\n    if (flags.global) {\n      error = 'globalFlagRemoved';\n      command = 'global add';\n    }\n    throw new MessageError(reporter.lang(error, `yarn ${command} ${exampleArgs.join(' ')}`));\n  }\n\n  await install(config, reporter, flags, lockfile);\n}\n\nexport async function wrapLifecycle(config: Config, flags: Object, factory: () => Promise<void>): Promise<void> {\n  await config.executeLifecycleScript('preinstall');\n\n  await factory();\n\n  // npm behaviour, seems kinda funky but yay compatibility\n  await config.executeLifecycleScript('install');\n  await config.executeLifecycleScript('postinstall');\n\n  if (!config.production) {\n    if (!config.disablePrepublish) {\n      await config.executeLifecycleScript('prepublish');\n    }","sourceCodeStart":1174,"sourceCodeEnd":1210,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/install.js#L1174-L1210","documentation":"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`.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Replace `yarn install <pkg>` with `yarn add <pkg>`.","For dev/peer/optional deps use `yarn add --dev|--peer|--optional <pkg>` (mirrored in exampleArgs at install.js:1172-1186).","For global install use `yarn global add <pkg>`.","If you genuinely meant to install from the lockfile, run `yarn install` with NO positional arguments."],"exampleFix":"// before\n$ yarn install lodash\n// after\n$ yarn add lodash","handlingStrategy":"validation","validationCode":"// Before invoking yarn programmatically, ensure install is called with no positional package args\nconst installArgs = process.argv.slice(2);\nconst wantsAdd = installArgs.length > 0; // any positional pkg -> must use `add`\nif (wantsAdd) {\n  console.error('Use `yarn add <pkg>` instead of `yarn install <pkg>`');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"// If you shell out to yarn, detect this MessageError and surface the migration hint\ntry {\n  await runYarn(['install', ...pkgs]);\n} catch (e) {\n  if (e && e.message && e.message.includes('installCommandRenamed')) {\n    throw new Error('Migration needed: use `yarn add` for package installation.');\n  }\n  throw e;\n}","preventionTips":["Treat `yarn install` as lockfile-only; never pass package names to it.","In migration docs, map every `npm install <pkg>` to `yarn add <pkg>`.","Lint CI scripts for `yarn install ` followed by a non-flag token."],"tags":["cli","install","migration","npm-compat"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}