{"record":{"id":"f12406c5ce1de81c","repo":"angular/angular-cli","slug":"could-not-find-angular-core-version","errorCode":null,"errorMessage":"Could not find \"@angular/core\" version.","messagePattern":"Could not find \"@angular/core\" version\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/service-worker/index.ts","lineNumber":41,"sourceCode":"import ts from 'typescript';\nimport { addDependency, addRootProvider, writeWorkspace } from '../utility';\nimport { addSymbolToNgModuleMetadata, insertImport } from '../utility/ast-utils';\nimport { applyToUpdateRecorder } from '../utility/change';\nimport { getDependency } from '../utility/dependency';\nimport { getAppModulePath, isStandaloneApp } from '../utility/ng-ast-utils';\nimport { relativePathToWorkspaceRoot } from '../utility/paths';\nimport { createProjectSchematic } from '../utility/project';\nimport { targetBuildNotFoundError } from '../utility/project-targets';\nimport { findAppConfig } from '../utility/standalone/app_config';\nimport { findBootstrapApplicationCall, getMainFilePath } from '../utility/standalone/util';\nimport { Builders } from '../utility/workspace-models';\nimport { Schema as ServiceWorkerOptions } from './schema';\n\nfunction addDependencies(): Rule {\n  return (host: Tree) => {\n    const coreDep = getDependency(host, '@angular/core');\n    if (!coreDep) {\n      throw new SchematicsException('Could not find \"@angular/core\" version.');\n    }\n\n    return addDependency('@angular/service-worker', coreDep.version);\n  };\n}\n\nfunction updateAppModule(mainPath: string): Rule {\n  return (host: Tree, context: SchematicContext) => {\n    context.logger.debug('Updating appmodule');\n\n    const modulePath = getAppModulePath(host, mainPath);\n    context.logger.debug(`module path: ${modulePath}`);\n\n    addImport(host, modulePath, 'ServiceWorkerModule', '@angular/service-worker');\n    addImport(host, modulePath, 'isDevMode', '@angular/core');\n\n    // register SW in application module\n    const importText = `","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/service-worker/index.ts#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n\"dependencies\": {}\n// after\n\"dependencies\": { \"@angular/core\": \"^18.0.0\" }","handlingStrategy":"validation","validationCode":"const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));\nif (!pkg.dependencies?.['@angular/core']) {\n  throw new Error('Install @angular/core before adding a service worker.');\n}","typeGuard":"function hasAngularCore(pkg: { dependencies?: Record<string, string> }): boolean {\n  return typeof pkg.dependencies?.['@angular/core'] === 'string';\n}","tryCatchPattern":"try {\n  await generateServiceWorkerSchematic(options);\n} catch (e) {\n  if (String(e.message).includes('Could not find \"@angular/core\" version')) {\n    console.error('Add @angular/core to dependencies and re-run the PWA schematic.');\n  } else throw e;\n}","preventionTips":["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"],"tags":["angular","schematics","service-worker","dependencies"],"backgroundTag":"missing-peer-dependency","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}