angular/angular-cli · error · Error
Specified module '${options.module}' does not exist.\nLooked
Error message
Specified module '${options.module}' does not exist.\nLooked in the following directories:\n ${candidatesDirs.join('\n ')} What it means
findModuleFromOptions is used when the user explicitly names a module via the `--module` option. After searching the given path and candidate directories for a file containing `@NgModule` matching the given name/path, the schematic throws when no such file exists.
Source
Thrown at packages/schematics/angular/utility/find-module.ts:74
if (options.moduleExt) {
candidateFiles.push(`${moduleBaseName}${options.moduleExt}`);
} else {
candidateFiles.push(
`${moduleBaseName}${MODULE_EXT}`,
`${moduleBaseName}${MODULE_EXT_LEGACY}`,
);
}
for (const c of candidatesDirs) {
for (const sc of candidateFiles) {
const scPath = join(c, sc);
if (host.exists(scPath) && host.readText(scPath).includes('@NgModule')) {
return normalize(scPath);
}
}
}
throw new Error(
`Specified module '${options.module}' does not exist.\n` +
`Looked in the following directories:\n ${candidatesDirs.join('\n ')}`,
);
}
}
/**
* Function to find the "closest" module to a generated file's path.
*/
export function findModule(
host: Tree,
generateDir: string,
moduleExt?: string,
routingModuleExt?: string,
): Path {
let dir: DirEntry | null = host.getDir('/' + generateDir);
let foundRoutingModule = false;
View on GitHub (pinned to bb72145f9a)
Solutions
- Check the directories listed in the error message and correct the --module path, e.g. `ng g c my-comp -m app`.
- Pass the path relative to src/app, including the directory: `-m paths/to/shared/shared.module`.
- Create the missing NgModule first (`ng g module shared`) or use --skip-import to skip module wiring.
Example fix
// before ng g c user --module=app.module // after ng g c user --module=app
Defensive patterns
Strategy: validation
Validate before calling
const modPath = path.resolve('src/app', `${options.module}.module.ts`);
if (!fs.existsSync(modPath) && !fs.existsSync(path.resolve('src/app', `${options.module}.ts`))) {
throw new Error(`--module target not found: ${options.module}`);
} Prevention
- Pass --module relative to src/app and let the CLI resolve extensions (`-m app`).
- Verify the module exists with a quick file check before scripting generation.
- Avoid relying on relative paths from nested directories in scripts.
When it happens
Trigger: Calling a schematic (component, directive, pipe, module) with `--module path/to/module` or `-m AppModule` where the path is misspelled, relative to the wrong directory, or the module file does not exist under any of the candidate directories.
Common situations: Typo in --module flag (e.g. `-m app.module` vs `app.module.ts`); module lives in a different folder than the generated component; path given without extension or with wrong case on case-sensitive filesystems; running from a subdirectory so relative paths resolve differently.
Related errors
- Could not find a non Routing NgModule.\nModules with suffix
- Option "project" is required.
- More than one module matches. Use the '--skip-import' option
- Project "${options.project}" does not exist.
- Project '${projectName}' not found in workspace path ${works
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/51b7e7b8e27f5e11.
Report an issue: GitHub.