angular/angular-cli · error · SchematicsException
Could not find version.
Error message
Could not find version.
What it means
Thrown by the server schematic's addDependencies when @angular/core cannot be found in the host's package.json dependencies, so its version cannot be read to align @angular/ssr with the framework version.
Source
Thrown at packages/schematics/angular/server/index.ts:145
if (!Array.isArray(include) || !include.includes('src/**/*.ts')) {
const filesPath = ['files'];
const files = new Set((json.get(filesPath) as string[] | undefined) ?? []);
files.add('src/' + serverMainEntryName);
json.modify(filesPath, [...files]);
}
const typePath = ['compilerOptions', 'types'];
const types = new Set((json.get(typePath) as string[] | undefined) ?? []);
types.add('node');
json.modify(typePath, [...types]);
};
}
function addDependencies(skipInstall: boolean | undefined): Rule {
return (host: Tree) => {
const coreDep = getPackageJsonDependency(host, '@angular/core');
if (coreDep === null) {
throw new SchematicsException('Could not find version.');
}
const install = skipInstall ? InstallBehavior.None : InstallBehavior.Auto;
return chain([
addDependency('@angular/ssr', latestVersions.AngularSSR, {
type: DependencyType.Default,
install,
}),
addDependency('@angular/platform-server', coreDep.version, {
type: DependencyType.Default,
install,
}),
addDependency('@types/node', latestVersions['@types/node'], {
type: DependencyType.Dev,
install,
}),
]);View on GitHub (pinned to bb72145f9a)
Solutions
- Ensure @angular/core is present in package.json dependencies (`npm i @angular/core`), then re-run the schematic.
- Run the schematic from the workspace root where the Angular app's package.json lives.
- Validate package.json parses (e.g. `npm pkg get dependencies`).
- Add @angular/ssr manually with `ng add @angular/ssr` if dependency installation is problematic.
Example fix
// before (package.json)
"dependencies": { "@angular/common": "^18.0.0" }
// after
"dependencies": { "@angular/core": "^18.0.0", "@angular/common": "^18.0.0" } Defensive patterns
Strategy: validation
Validate before calling
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
if (!pkg.dependencies?.['@angular/core']) {
throw new Error('@angular/core must be a dependency before running the server schematic.');
} Type guard
function hasCoreDep(pkg: { dependencies?: Record<string, string> }): boolean {
return typeof pkg.dependencies?.['@angular/core'] === 'string';
} Try / catch
try {
await generateServerSchematic(options);
} catch (e) {
if (String(e.message).includes('Could not find version')) {
console.error('Install @angular/core first, then re-run.');
} else throw e;
} Prevention
- Always scaffold via ng new / ng add so dependencies are complete
- Never hand-strip @angular/core from package.json
- Run schematics from the workspace root
- Validate package.json parses before codegen steps
When it happens
Trigger: Running `ng generate @angular/ssr:server` (or the server schematic Rule) in a workspace whose package.json lacks @angular/core in dependencies, or where getPackageJsonDependency returns null due to malformed package.json.
Common situations: Generating into a directory outside a proper Angular app; package.json manually stripped of dependencies; running the schematic in a bare/empty tree during tests; corrupted package.json JSON.
Related errors
- Package dependency "${name}" already exists with a different
- Package ${JSON.stringify(name)} was found but does not suppo
- Could not find "@angular/core" version.
- Could not find package.json
- Package ${JSON.stringify(name)} was not found in package.jso
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/bc74c1b8443aa76e.
Report an issue: GitHub.