{"record":{"id":"de2824a4109fc07b","repo":"angular/angular-cli","slug":"invalid-semver-version-for-this-name-this","errorCode":null,"errorMessage":"Invalid semver version for ${this.name}: \"${this.#version}\"","messagePattern":"Invalid semver version for (.+?): \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/package-managers/package-manager.ts","lineNumber":429,"sourceCode":"      return pkgJson.name;\n    } catch {\n      return undefined;\n    }\n  }\n\n  /**\n   * Gets the version of the package manager binary.\n   */\n  async getVersion(): Promise<string> {\n    if (this.#version) {\n      return this.#version;\n    }\n\n    const { stdout } = await this.#run(this.descriptor.versionCommand);\n    this.#version = stdout.trim();\n\n    if (!valid(this.#version)) {\n      throw new Error(`Invalid semver version for ${this.name}: \"${this.#version}\"`);\n    }\n\n    return this.#version;\n  }\n\n  /**\n   * Gets the installed details of a package from the project's dependencies.\n   * @param packageName The name of the package to check.\n   * @returns A promise that resolves to the installed package details, or `null` if the package is not installed.\n   */\n  async getInstalledPackage(packageName: string): Promise<InstalledPackage | null> {\n    const cache = await this.#populateDependencyCache();\n\n    return cache.get(packageName) ?? null;\n  }\n\n  /**\n   * Gets a map of all top-level dependencies installed in the project.","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/package-managers/package-manager.ts#L411-L447","documentation":"getVersion() runs the package manager's version command (e.g. `npm --version`), trims stdout, and validates the result with semver's `valid()`. If the output is not a valid semver string, this Error is thrown naming the package manager and the offending raw output. The library enforces semver because the version is used for feature comparisons and compatibility checks.","triggerScenarios":"Calling version() or acquireTempPackage() (which call getVersion()) when the version command prints something that is not a bare semver version — e.g. extra labels, warning text, or a non-version string.","commonSituations":"Package manager installed from a nonstandard source (nightly, fork, OS distro patch) printing versions like '1.2.3-beta.0+local' variants or '8.19.2 (custom build)'; shell profile echoing banners before command output; wrapper scripts printing deprecation notices; a corrupted or shimmed binary on PATH.","solutions":["Run the version command manually (`npm --version` / `yarn --version` / `pnpm --version`) and inspect the raw output for extra text.","Remove shell profile lines or wrapper scripts that echo output before the version string.","Reinstall the package manager from the official channel (`npm i -g npm@latest`, corepack) to replace nonstandard builds.","Ensure the binary on PATH is the real package manager (`which npm`) and not a shim printing extra text.","If a prerelease with unusual formatting is required, use one whose version output passes semver.valid()."],"exampleFix":"// before: shell profile prints banner on every command\n// echo \"Welcome to my shell\"   <- in ~/.bashrc, pollutes captured output\n\n// after: guard profile output for non-interactive shells\necho 'command -v npm >/dev/null 2>&1 && [ -z \"$PS1\" ] || echo \"Welcome to my shell\"' >> ~/.bashrc","handlingStrategy":"validation","validationCode":"import { exec } from 'node:child_process';\nimport { promisify } from 'node:util';\nimport { valid } from 'semver';\nconst run = promisify(exec);\nconst { stdout } = await run('npm --version');\nif (!valid(stdout.trim())) {\n  throw new Error(`Package manager reports invalid version: \"${stdout.trim()}\"`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const version = await pm.getVersion();\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Invalid semver version for')) {\n    console.error('Package manager output is not a valid semver:', e.message);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Install package managers from official channels (npm registry, corepack) rather than forks or distro-patched builds.","Keep shell profiles silent for non-interactive shells so command output is not polluted.","Check `which npm`/`which yarn` to ensure no shim or wrapper shadows the real binary.","Validate `npm --version` output in environment setup scripts before running CLI automation.","Pin the package manager version (e.g. via corepack `packageManager` field) for reproducible, parseable output."],"tags":["semver","version","package-manager","angular-cli"],"backgroundTag":"invalid-semver-version","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}