{"record":{"id":"c1169d5f064afb79","repo":"ionic-team/ionic-framework","slug":"could-not-find-file-for-path-path","errorCode":null,"errorMessage":"Could not find file for path: ${path}","messagePattern":"Could not find file for path: (.+?)","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/angular/src/schematics/utils/ast.ts","lineNumber":13,"sourceCode":"import type { Tree } from '@angular-devkit/schematics';\nimport { SchematicsException } from '@angular-devkit/schematics';\nimport { addSymbolToNgModuleMetadata, insertImport } from '@schematics/angular/utility/ast-utils';\nimport { applyToUpdateRecorder } from '@schematics/angular/utility/change';\nimport * as ts from 'typescript';\n\n/**\n * Reads file given path and returns TypeScript source file.\n */\nfunction getSourceFile(host: Tree, path: string): ts.SourceFile {\n  const buffer = host.read(path);\n  if (!buffer) {\n    throw new SchematicsException(`Could not find file for path: ${path}`);\n  }\n  const content = buffer.toString();\n  const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);\n  return source;\n}\n\n/**\n * Import and add module to root app module.\n */\nexport function addIonicModuleImportToNgModule(host: Tree, modulePath: string): void {\n  const recorder = host.beginUpdate(modulePath);\n  const moduleSource = getSourceFile(host, modulePath) as any;\n\n  const ionicModuleChange = insertImport(moduleSource, modulePath, 'IonicModule', '@ionic/angular');\n\n  applyToUpdateRecorder(recorder, [ionicModuleChange]);\n\n  const metadataChange = addSymbolToNgModuleMetadata(moduleSource, modulePath, 'imports', 'IonicModule.forRoot({})');","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/ionic-team/ionic-framework/blob/625f9c38ad8c5db8a6c12df5c1622a36da90f9e3/packages/angular/src/schematics/utils/ast.ts#L1-L31","documentation":"Thrown by getSourceFile() in the schematics AST utility when host.read(path) returns no buffer - i.e. the file at the given path does not exist in the schematic's virtual tree. getSourceFile is used by addIonicModuleImportToNgModule to parse app.module.ts (or another module) with the TypeScript compiler, so a missing module file aborts the edit.","triggerScenarios":"The schematic (or a downstream utility) calls addIonicModuleImportToNgModule/addSymbolToNgModuleMetadata with a modulePath that does not exist in the tree - for example a non-default app module name, a standalone-components project with no NgModule, or a path computed from an incorrect sourceRoot.","commonSituations":"Running Ionic Add in a project that uses standalone APIs and has no app.module.ts; a custom sourceRoot in angular.json; the schematic was given/derived a wrong module path; partial tree state during a custom schematic that wraps Ionic's utilities.","solutions":["Confirm the module file exists at the path passed in (default is src/app/app.module.ts) before running the schematic.","If your app is standalone (no NgModule), use the standalone-compatible Ionic Add flow / provideIonicAngular instead of the NgModule-import step.","Check angular.json `sourceRoot` and align the schematic's expected path with your project layout.","If authoring a custom schematic that calls these utils, guard host.read and resolve the real module path first."],"exampleFix":"// before: schematic computes a path that doesn't exist\naddIonicModuleImportToNgModule(host, 'src/app/app.module.ts'); // file is absent in standalone app\n\n// after: verify existence, else skip / use standalone provider\nconst buffer = host.read('src/app/app.module.ts');\nif (!buffer) {\n  // standalone app: add provideIonicAngular() to main.ts instead\n} else {\n  addIonicModuleImportToNgModule(host, 'src/app/app.module.ts');\n}","handlingStrategy":"validation","validationCode":"// Confirm the module file exists before invoking the AST utility:\nif (host.read(modulePath)) {\n  addIonicModuleImportToNgModule(host, modulePath);\n} else {\n  // standalone app: add provideIonicAngular() to main.ts instead\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure app.module.ts exists (non-standalone setup) before running Ionic Add.","For standalone apps, use the standalone provider flow.","Keep angular.json sourceRoot consistent with the module path the schematic expects."],"tags":["angular","schematics","build-tooling","typescript","ast","filesystem"],"backgroundTag":null,"analyzedSha":"625f9c38ad8c5db8a6c12df5c1622a36da90f9e3","analyzedAt":"2026-08-12T16:00:25.413Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}