{"record":{"id":"a79b831fcaeac57e","repo":"angular/components","slug":"cannot-create-an-angular-material-theme-because","errorCode":null,"errorMessage":"Cannot create an Angular Material theme because\n          ${themePath} already exists. Skipping theme generation.","messagePattern":"Cannot create an Angular Material theme because\n          (.+?) already exists\\. Skipping theme generation\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/material/schematics/ng-add/theming/theming.ts","lineNumber":75,"sourceCode":"  const workspace = await readWorkspace(host);\n  const project = getProjectFromWorkspace(workspace, projectName);\n  const stylesPath = getProjectStyleFile(project, 'scss');\n  const themeContent = createTheme(palettes);\n\n  if (!stylesPath) {\n    if (!project.sourceRoot) {\n      throw new SchematicsException(\n        `Could not find source root for project: \"${projectName}\". ` +\n          `Please make sure that the \"sourceRoot\" property is set in the workspace config.`,\n      );\n    }\n\n    // Normalize the path through the devkit utilities because we want to avoid having\n    // unnecessary path segments and windows backslash delimiters.\n    const themePath = normalize(join(project.sourceRoot, defaultThemeFilename));\n\n    if (host.exists(themePath)) {\n      logger.warn(`Cannot create an Angular Material theme because\n          ${themePath} already exists. Skipping theme generation.`);\n      return noop();\n    }\n\n    host.create(themePath, themeContent);\n    return addThemeStyleToTarget(projectName, 'build', themePath, logger);\n  }\n\n  const insertion = new InsertChange(stylesPath, 0, themeContent);\n  const recorder = host.beginUpdate(stylesPath);\n\n  recorder.insertLeft(insertion.pos, insertion.toAdd);\n  host.commitUpdate(recorder);\n  return noop();\n}\n\n/** Adds a theming style entry to the given project target options. */\nfunction addThemeStyleToTarget(","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/schematics/ng-add/theming/theming.ts#L57-L93","documentation":"This is a warning emitted by the Angular Material ng-add theming schematic when the theme file it intends to create (e.g. src/styles.scss themed path) already exists in the project. The schematic refuses to overwrite the existing file and skips theme generation, returning a noop instead of aborting. It is not a thrown error; it tells you the file was left untouched so you can review or merge it manually.","triggerScenarios":"Running `ng add @angular/material` (which invokes addThemeToAppStyles -> insertTheme) when a file at normalize(join(project.sourceRoot, defaultThemeFilename)) already passes host.exists(), i.e. a theme file with the default name (e.g. src/custom-theme.scss) already exists from a previous `ng add` run or was created manually.","commonSituations":"Re-running `ng add @angular/material` after a partial install; upgrading Material via ng add again; a teammate committed the generated theme file and another dev runs ng add; manually scaffolding a file named custom-theme.scss before running the schematic.","solutions":["Delete or rename the existing theme file (e.g. src/custom-theme.scss) and re-run `ng add @angular/material`.","Keep the existing file and add/verify the theme mixin imports (@include mat.core(); mat.define-theme) manually inside it.","If the existing theme is already correct, do nothing — the warning is benign and the schematic intentionally skipped generation."],"exampleFix":"// before: re-run ng add fails to generate\nsrc/custom-theme.scss already exists\n// after\ndelete src/custom-theme.scss, then: ng add @angular/material","handlingStrategy":"validation","validationCode":"import {normalize} from '@angular-devkit/core';\nimport {join} from 'path';\nconst themePath = normalize(join(project.sourceRoot || 'src', 'custom-theme.scss'));\nif (host.exists(themePath)) {\n  // rename it or plan to edit it manually before running ng add\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never name a hand-written stylesheet src/custom-theme.scss before running ng add @angular/material.","Run ng add once on a fresh branch and commit the generated theme file.","Check for the theme file's existence before re-running the schematic."],"tags":["angular","schematics","material-theme","ng-add"],"backgroundTag":"schematic-theme-file-already-exists","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}