angular/angular-cli · error · SchematicsException
Could not find "@angular/core" version.
Error message
Could not find "@angular/core" version.
What it means
Thrown by the service-worker schematic's addDependencies when @angular/core is absent from the workspace package.json, so its version cannot be used to pin @angular/service-worker to the matching Angular version.
Source
Thrown at packages/schematics/angular/service-worker/index.ts:41
import ts from 'typescript';
import { addDependency, addRootProvider, writeWorkspace } from '../utility';
import { addSymbolToNgModuleMetadata, insertImport } from '../utility/ast-utils';
import { applyToUpdateRecorder } from '../utility/change';
import { getDependency } from '../utility/dependency';
import { getAppModulePath, isStandaloneApp } from '../utility/ng-ast-utils';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { createProjectSchematic } from '../utility/project';
import { targetBuildNotFoundError } from '../utility/project-targets';
import { findAppConfig } from '../utility/standalone/app_config';
import { findBootstrapApplicationCall, getMainFilePath } from '../utility/standalone/util';
import { Builders } from '../utility/workspace-models';
import { Schema as ServiceWorkerOptions } from './schema';
function addDependencies(): Rule {
return (host: Tree) => {
const coreDep = getDependency(host, '@angular/core');
if (!coreDep) {
throw new SchematicsException('Could not find "@angular/core" version.');
}
return addDependency('@angular/service-worker', coreDep.version);
};
}
function updateAppModule(mainPath: string): Rule {
return (host: Tree, context: SchematicContext) => {
context.logger.debug('Updating appmodule');
const modulePath = getAppModulePath(host, mainPath);
context.logger.debug(`module path: ${modulePath}`);
addImport(host, modulePath, 'ServiceWorkerModule', '@angular/service-worker');
addImport(host, modulePath, 'isDevMode', '@angular/core');
// register SW in application module
const importText = `View on GitHub (pinned to bb72145f9a)
Solutions
- Install @angular/core (`npm i @angular/core`) and re-run the service-worker/PWA schematic.
- Run the schematic from the Angular workspace root.
- Verify package.json contains "@angular/core" under dependencies (`npm pkg get dependencies.@angular/core`).
- Repair or restore package.json if it is malformed.
Example fix
// before
"dependencies": {}
// after
"dependencies": { "@angular/core": "^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('Install @angular/core before adding a service worker.');
} Type guard
function hasAngularCore(pkg: { dependencies?: Record<string, string> }): boolean {
return typeof pkg.dependencies?.['@angular/core'] === 'string';
} Try / catch
try {
await generateServiceWorkerSchematic(options);
} catch (e) {
if (String(e.message).includes('Could not find "@angular/core" version')) {
console.error('Add @angular/core to dependencies and re-run the PWA schematic.');
} else throw e;
} Prevention
- Run ng add @angular/pwa from a fully installed Angular workspace
- Keep package.json intact and committed
- Run schematics at the workspace root
- Re-run npm install after dependency edits
When it happens
Trigger: Running `ng generate @angular/pwa` / service-worker schematic where getDependency(host, '@angular/core') returns null — @angular/core missing from package.json dependencies or the package.json unreadable/malformed.
Common situations: Adding PWA to a non-Angular or partially scaffolded workspace; package.json edited to remove dependencies; running the schematic in a subfolder without a package.json; failed npm install leaving package.json incomplete.
Related errors
- Could not find version.
- Service worker requires a project type of "application".
- No "production" configuration found for build target. The "s
- Package dependency "${name}" already exists with a different
- Option "project" is required.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/f12406c5ce1de81c.
Report an issue: GitHub.