{"record":{"id":"660929acbe437eac","repo":"facebook/docusaurus","slug":"invalid-package-manager-choice-packagemanager","errorCode":null,"errorMessage":"Invalid package manager choice ${packageManager}. Must be one of ${PackageManagers.join(', ')}","messagePattern":"Invalid package manager choice (.+?)\\. Must be one of (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-docusaurus/src/index.ts","lineNumber":115,"sourceCode":"          message: 'Select a package manager...',\n          choices,\n        },\n        {\n          onCancel() {\n            logger.info`Falling back to name=${DefaultPackageManager}`;\n          },\n        },\n      )) as {packageManager?: PackageManager}\n    ).packageManager ?? DefaultPackageManager\n  );\n}\n\nasync function getPackageManager(\n  dest: string,\n  {packageManager, skipInstall}: CLIOptions,\n): Promise<PackageManager> {\n  if (packageManager && !PackageManagers.includes(packageManager)) {\n    throw new Error(\n      `Invalid package manager choice ${packageManager}. Must be one of ${PackageManagers.join(\n        ', ',\n      )}`,\n    );\n  }\n\n  return (\n    // If dest already contains a lockfile (e.g. if using a local template), we\n    // always use that instead\n    (await findPackageManagerFromLockFile(dest)) ??\n    packageManager ??\n    (await findPackageManagerFromLockFile('.')) ??\n    findPackageManagerFromUserAgent() ??\n    // This only happens if the user has a global installation in PATH\n    (skipInstall ? DefaultPackageManager : await askForPackageManagerChoice())\n  );\n}\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/create-docusaurus/src/index.ts#L97-L133","documentation":"Thrown by getPackageManager() in create-docusaurus when the --package-manager CLI option is set to a value that is not one of the supported keys: npm, yarn, pnpm, bun (the keys of LockfileNames in packages/create-docusaurus/src/constants.ts). The check exists because the CLI flag is a raw string from argv and TypeScript cannot enforce the PackageManager union at runtime. Docusaurus needs a known manager so it can later compute the install command and lockfile name.","triggerScenarios":"Running create-docusaurus with --package-manager pnpm2, --package-manager npm@9, --package-manager chocolatey, or any typo like --package-manager yrn. Reached in the main init flow the first time getPackageManager validates the CLIOptions.","commonSituations":"Typos in the flag value; passing a version-qualified manager name (npm@10) instead of just npm; passing a manager that exists on the machine but is not in the supported set (e.g. volta); shell completion or a script feeding an unexpected value.","solutions":["Re-run with one of the supported values: --package-manager npm | yarn | pnpm | bun.","Omit the flag entirely and let create-docusaurus detect the manager from a lockfile in the dest or cwd, or from the npm_config_user_agent env var.","If you need a manager outside the supported set, edit packages/create-docusaurus/src/constants.ts LockfileNames and PackageManagers (maintainer only)."],"exampleFix":"# before\nnpx create-docusaurus my-site --package-manager pnpm2\n# after\nnpx create-docusaurus my-site --package-manager pnpm","handlingStrategy":"validation","validationCode":"import {PackageManagers, type PackageManager} from './constants.js';\nfunction assertPackageManager(pm: string): asserts pm is PackageManager {\n  if (!PackageManagers.includes(pm as PackageManager)) {\n    throw new Error(\n      `Invalid package manager choice ${pm}. Must be one of ${PackageManagers.join(', ')}`,\n    );\n  }\n}\nassertPackageManager(argv.packageManager);","typeGuard":"import {PackageManagers, type PackageManager} from './constants.js';\nconst isPackageManager = (v: unknown): v is PackageManager =>\n  typeof v === 'string' && (PackageManagers as string[]).includes(v);","tryCatchPattern":null,"preventionTips":["Validate the --package-manager flag in your CLI wrapper against PackageManagers before forwarding.","Prefer letting create-docusaurus auto-detect (lockfile / user-agent) rather than passing the flag.","Document only the four supported values wherever you tell users to pass the flag."],"tags":["create-docusaurus","cli","package-manager","validation"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}