angular/angular-cli · error · Error
An unexpected error happened; could not determine version fo
Error message
An unexpected error happened; could not determine version for package ${name}. What it means
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.
Source
Thrown at packages/angular/cli/src/commands/update/update-resolver.ts:490
const name = npmPackageJson.name;
const packageJsonRange = allDependencies.get(name);
if (!packageJsonRange) {
throw new Error(`Package ${JSON.stringify(name)} was not found in package.json.`);
}
const localPkgJson = getInstalledPackageJson(name, workspaceRoot);
let installedVersion = localPkgJson?.version;
if (!installedVersion) {
installedVersion = (await getSatisfyingVersion(
registryClient,
npmPackageJson,
packageJsonRange,
)) as VersionRange | undefined;
}
if (!installedVersion) {
throw new Error(
`An unexpected error happened; could not determine version for package ${name}.`,
);
}
const installedPackageJson =
localPkgJson || (await registryClient.getManifest(name, installedVersion));
if (!installedPackageJson) {
throw new Error(
`An unexpected error happened; package ${name} has no version ${installedVersion}.`,
);
}
let targetVersion: VersionRange | undefined = packages.get(name);
if (targetVersion) {
const distTags = npmPackageJson['dist-tags'] ?? {};
let resolvedVersion: string | undefined =
distTags[targetVersion] ?? (targetVersion === 'next' ? distTags['latest'] : undefined);
View on GitHub (pinned to bb72145f9a)
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.
Example fix
// before ng update @angular/core // node_modules missing // after npm install ng update @angular/core
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync, readFileSync } from 'fs';
const manifest = `node_modules/${name}/package.json`;
if (!existsSync(manifest) || !JSON.parse(readFileSync(manifest,'utf8')).version) {
throw new Error(`Run install first: ${name} is not installed`);
} Type guard
function isInstalled(name) {
try {
return typeof require(`${name}/package.json`).version === 'string';
} catch { return false; }
} Try / catch
try {
await ngUpdate([name]);
} catch (e) {
if (String(e.message).includes('could not determine version')) {
execSync('npm install', { stdio: 'inherit' }); // restore node_modules, then retry
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find the '${builderConf}' builder's node package.
- Package ${name} is not installed.
- An unexpected error happened; package ${name} has no version
- Package ${JSON.stringify(pkgName)} is not in package.json.
- Repository is not clean. Update changes will be mixed with p
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/269cecb2887ded97.
Report an issue: GitHub.