{"record":{"id":"269cecb2887ded97","repo":"angular/angular-cli","slug":"an-unexpected-error-happened-could-not-determine","errorCode":null,"errorMessage":"An unexpected error happened; could not determine version for package ${name}.","messagePattern":"An unexpected error happened; could not determine version for package (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/commands/update/update-resolver.ts","lineNumber":490,"sourceCode":"  const name = npmPackageJson.name;\n  const packageJsonRange = allDependencies.get(name);\n  if (!packageJsonRange) {\n    throw new Error(`Package ${JSON.stringify(name)} was not found in package.json.`);\n  }\n\n  const localPkgJson = getInstalledPackageJson(name, workspaceRoot);\n  let installedVersion = localPkgJson?.version;\n\n  if (!installedVersion) {\n    installedVersion = (await getSatisfyingVersion(\n      registryClient,\n      npmPackageJson,\n      packageJsonRange,\n    )) as VersionRange | undefined;\n  }\n\n  if (!installedVersion) {\n    throw new Error(\n      `An unexpected error happened; could not determine version for package ${name}.`,\n    );\n  }\n\n  const installedPackageJson =\n    localPkgJson || (await registryClient.getManifest(name, installedVersion));\n  if (!installedPackageJson) {\n    throw new Error(\n      `An unexpected error happened; package ${name} has no version ${installedVersion}.`,\n    );\n  }\n\n  let targetVersion: VersionRange | undefined = packages.get(name);\n  if (targetVersion) {\n    const distTags = npmPackageJson['dist-tags'] ?? {};\n    let resolvedVersion: string | undefined =\n      distTags[targetVersion] ?? (targetVersion === 'next' ? distTags['latest'] : undefined);\n","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/commands/update/update-resolver.ts#L472-L508","documentation":"Thrown by _buildPackageInfo when neither the locally installed package's package.json nor any other source could supply an installed version for the package being updated. The CLI needs the installed version to compute the update range but found nothing on disk or in the registry metadata.","triggerScenarios":"The package is listed in package.json but not actually installed (missing node_modules); the installed package directory exists but its package.json is missing/corrupt so localPkgJson?.version is undefined; registry lookups also failed to yield a version.","commonSituations":"Fresh checkout without running npm install; interrupted install leaving broken node_modules; pnpm/yarn PnP layouts the CLI cannot read; corrupted node_modules after a failed upgrade.","solutions":["Run your package manager's install command (npm install / yarn / pnpm install) to restore node_modules.","Verify node_modules/<pkg>/package.json exists and has a version field.","Delete node_modules and lockfile and reinstall if corrupted.","Ensure you run ng update from the workspace root."],"exampleFix":"// before\nng update @angular/core  // node_modules missing\n// after\nnpm install\nng update @angular/core","handlingStrategy":"validation","validationCode":"import { existsSync, readFileSync } from 'fs';\nconst manifest = `node_modules/${name}/package.json`;\nif (!existsSync(manifest) || !JSON.parse(readFileSync(manifest,'utf8')).version) {\n  throw new Error(`Run install first: ${name} is not installed`);\n}","typeGuard":"function isInstalled(name) {\n  try {\n    return typeof require(`${name}/package.json`).version === 'string';\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  await ngUpdate([name]);\n} catch (e) {\n  if (String(e.message).includes('could not determine version')) {\n    execSync('npm install', { stdio: 'inherit' }); // restore node_modules, then retry\n  }\n}","preventionTips":["Run npm/pnpm/yarn install after cloning or pulling.","Do not delete or hand-edit files inside node_modules.","Keep a lockfile committed so installs are reproducible.","Run ng update from the workspace root."],"tags":["angular-cli","node-modules","version-detection","update"],"backgroundTag":"cannot-determine-installed-version","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}