ionic-team/ionic-framework · error · SchematicsException
Could not find file for path: ${path}
Error message
Could not find file for path: ${path} What it means
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.
Source
Thrown at packages/angular/src/schematics/utils/ast.ts:13
import type { Tree } from '@angular-devkit/schematics';
import { SchematicsException } from '@angular-devkit/schematics';
import { addSymbolToNgModuleMetadata, insertImport } from '@schematics/angular/utility/ast-utils';
import { applyToUpdateRecorder } from '@schematics/angular/utility/change';
import * as ts from 'typescript';
/**
* Reads file given path and returns TypeScript source file.
*/
function getSourceFile(host: Tree, path: string): ts.SourceFile {
const buffer = host.read(path);
if (!buffer) {
throw new SchematicsException(`Could not find file for path: ${path}`);
}
const content = buffer.toString();
const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
return source;
}
/**
* Import and add module to root app module.
*/
export function addIonicModuleImportToNgModule(host: Tree, modulePath: string): void {
const recorder = host.beginUpdate(modulePath);
const moduleSource = getSourceFile(host, modulePath) as any;
const ionicModuleChange = insertImport(moduleSource, modulePath, 'IonicModule', '@ionic/angular');
applyToUpdateRecorder(recorder, [ionicModuleChange]);
const metadataChange = addSymbolToNgModuleMetadata(moduleSource, modulePath, 'imports', 'IonicModule.forRoot({})');View on GitHub (pinned to 625f9c38ad)
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.
Example fix
// before: schematic computes a path that doesn't exist
addIonicModuleImportToNgModule(host, 'src/app/app.module.ts'); // file is absent in standalone app
// after: verify existence, else skip / use standalone provider
const buffer = host.read('src/app/app.module.ts');
if (!buffer) {
// standalone app: add provideIonicAngular() to main.ts instead
} else {
addIonicModuleImportToNgModule(host, 'src/app/app.module.ts');
} Defensive patterns
Strategy: validation
Validate before calling
// Confirm the module file exists before invoking the AST utility:
if (host.read(modulePath)) {
addIonicModuleImportToNgModule(host, modulePath);
} else {
// standalone app: add provideIonicAngular() to main.ts instead
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Ionic Add requires a project type of "application".
- Could not find project: ${projectName}
- Invalid projectType for ${projectName}: ${config.projectType
- Invalid builder for ${projectName}: ${buildConfig.builder}
- Could not find (${path})
AI-assisted analysis of ionic-team/ionic-framework@625f9c38ad (2026-08-12).
Data as JSON: /api/errors/c1169d5f064afb79.
Report an issue: GitHub.