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

  1. Ensure @angular/core is present in package.json dependencies (`npm i @angular/core`), then re-run the schematic.
  2. Run the schematic from the workspace root where the Angular app's package.json lives.
  3. Validate package.json parses (e.g. `npm pkg get dependencies`).
  4. 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

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


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/bc74c1b8443aa76e. Report an issue: GitHub.