{"record":{"id":"a466e058d94aa009","repo":"angular/components","slug":"could-not-find-the-project-main-file-inside-of-the","errorCode":null,"errorMessage":"Could not find the project main file inside of the workspace config (${project.sourceRoot})","messagePattern":"Could not find the project main file inside of the workspace config \\((.+?)\\)","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"src/cdk/schematics/utils/project-main-file.ts","lineNumber":23,"sourceCode":" * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {Path} from '@angular-devkit/core';\nimport {SchematicsException} from '@angular-devkit/schematics';\nimport {getProjectTargetOptions} from './project-targets';\nimport {ProjectDefinition} from '@schematics/angular/utility';\n\n/** Looks for the main TypeScript file in the given project and returns its path. */\nexport function getProjectMainFile(project: ProjectDefinition): Path {\n  const buildOptions = getProjectTargetOptions(project, 'build');\n\n  // `browser` is for the `@angular-devkit/build-angular:application` builder while\n  // `main` is for the `@angular-devkit/build-angular:browser` builder.\n  const mainPath = (buildOptions['browser'] || buildOptions['main']) as Path | undefined;\n\n  if (!mainPath) {\n    throw new SchematicsException(\n      `Could not find the project main file inside of the ` +\n        `workspace config (${project.sourceRoot})`,\n    );\n  }\n\n  return mainPath;\n}\n","sourceCodeStart":5,"sourceCodeEnd":31,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/schematics/utils/project-main-file.ts#L5-L31","documentation":"getProjectMainFile in src/cdk/schematics/utils/project-main-file.ts resolves the application's entry point by reading the \"browser\" (application builder) or \"main\" (browser builder) option from the project's build target options. If neither option is defined, the schematic cannot locate main.ts and throws this SchematicsException, including the project's sourceRoot for context.","triggerScenarios":"Running CDK/Material schematics against a project whose build target (build or the target resolved by getProjectTargetOptions) has no \"main\" or \"browser\" option — e.g. library projects, custom builders (ngx-build-plus, custom executors), or hand-trimmed angular.json entries.","commonSituations":"Running `ng add @angular/material` or `ng generate @angular/cdk:xxx` targeting a library instead of an application; migrating from older builder configs where main was moved or renamed; Nx/custom executor setups that keep the entry point in a different key.","solutions":["Run the schematic with --project pointing at an application, not a library; libraries have no main file.","Add \"options\": { \"main\": \"src/main.ts\" } (or \"browser\" for the application builder) to the project's build target in angular.json.","If you use a custom builder, expose the entry point via the standard main/browser option key so schematics can find it.","Check which build target the schematic inspects and ensure that specific target (e.g. \"build\") defines the entry file."],"exampleFix":"// before (angular.json)\n\"build\": { \"builder\": \"@angular-devkit/build-angular:browser\", \"options\": {} }\n// after (angular.json)\n\"build\": { \"builder\": \"@angular-devkit/build-angular:browser\", \"options\": { \"main\": \"src/main.ts\" } }","handlingStrategy":"validation","validationCode":"const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));\nconst p = ws.projects[name];\nconst opts = p?.architect?.build?.options ?? {};\nif (!opts.main && !opts.browser) {\n  throw new Error(`Project \"${name}\" has no main/browser entry point; is it an application?`);\n}","typeGuard":"function hasMainFile(opts: Record<string, unknown> | undefined): opts is Record<string, unknown> & { main?: string; browser?: string } {\n  return !!opts && (typeof opts.main === 'string' || typeof opts.browser === 'string');\n}","tryCatchPattern":"try {\n  await generateSchematic('nav', { project: name });\n} catch (e) {\n  if (String(e.message).includes('Could not find the project main file')) {\n    console.error(`\"${name}\" has no main file — run against an application project.`);\n  } else throw e;\n}","preventionTips":["Only run app-oriented schematics against application projects, never libraries.","Keep the standard main/browser option in the build target even with custom builders.","Audit angular.json after migrations to ensure build options survived."],"tags":["angular","schematics","workspace-config","main-file"],"backgroundTag":"missing-build-option","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}