{"record":{"id":"75e40864d20a5fdf","repo":"angular/angular-cli","slug":"file-replacement-with-does-not-exist","errorCode":null,"errorMessage":"File replacement (with) does not exist","messagePattern":"File replacement \\(with\\) does not exist","errorType":"exception","errorClass":"MissingFileReplacementException","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/utils/normalize-file-replacements.ts","lineNumber":38,"sourceCode":"  replace: string;\n  with: string;\n}\n\nexport function normalizeFileReplacements(\n  fileReplacements: FileReplacement[],\n  workspaceRoot: string,\n): NormalizedFileReplacement[] {\n  if (fileReplacements.length === 0) {\n    return [];\n  }\n\n  const normalizedReplacement = fileReplacements.map((replacement) =>\n    normalizeFileReplacement(replacement, workspaceRoot),\n  );\n\n  for (const { replace, with: replacementWith } of normalizedReplacement) {\n    if (!existsSync(replacementWith)) {\n      throw new MissingFileReplacementException(replacementWith);\n    }\n\n    if (!existsSync(replace)) {\n      throw new MissingFileReplacementException(replace);\n    }\n  }\n\n  return normalizedReplacement;\n}\n\nfunction normalizeFileReplacement(\n  fileReplacement: FileReplacement,\n  root: string,\n): NormalizedFileReplacement {\n  let replacePath: string;\n  let withPath: string;\n  if (fileReplacement.src && fileReplacement.replaceWith) {\n    replacePath = fileReplacement.src;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/utils/normalize-file-replacements.ts#L20-L56","documentation":"normalizeFileReplacements validates each file replacement configured for the build before webpack runs. After resolving `replace` and `with` paths against the workspace root, it checks both files exist on disk; if the `with` (replacement source) file does not exist, MissingFileReplacementException is thrown with that path. The build aborts rather than silently substituting a non-existent file.","triggerScenarios":"ng build with angular.json fileReplacements entry where the \"with\" (or legacy \"replaceWith\") path, resolved against workspaceRoot, does not exist on disk — e.g. src/environments/environment.prod.ts was deleted/renamed, or the path is misspelled or relative to the wrong root.","commonSituations":"Environment files removed in refactors but left in angular.json, branch switches where environment.*.ts files are gitignored or absent, monorepo configs where paths must be relative to workspaceRoot not the project dir, and configuration-driven replacements (dev/prod) that only exist for some targets.","solutions":["Verify the \"with\" path exists relative to the workspace root; correct or remove the fileReplacements entry in angular.json.","If the file was renamed, update the replacement to the new name (e.g. src/environments/environment.development.ts).","Run ls on the resolved path (workspaceRoot + \"with\" value) to confirm the exact location the CLI expects."],"exampleFix":"// before (angular.json)\n\"fileReplacements\": [{ \"replace\": \"src/environments/environment.ts\", \"with\": \"src/environments/environment.prod.ts\" }]\n// after (file actually named environment.production.ts)\n\"fileReplacements\": [{ \"replace\": \"src/environments/environment.ts\", \"with\": \"src/environments/environment.production.ts\" }]","handlingStrategy":"validation","validationCode":"// Check before running the build\nconst { existsSync } = require('fs');\nconst { resolve } = require('path');\nfor (const fr of schema.fileReplacements ?? []) {\n  if (!existsSync(resolve(workspaceRoot, fr.with))) {\n    throw new Error(`fileReplacements 'with' target missing: ${fr.with}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runBuild(schema);\n} catch (err) {\n  if (err?.constructor?.name === 'MissingFileReplacementException' || /does not exist/.test(err?.message ?? '')) {\n    console.error('Fix or remove the fileReplacements entry named in the message, then rebuild.');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Treat environment files as committed source (never gitignore environment.*.ts referenced by replacements).","After renaming/moving environment files, grep angular.json for stale paths.","Write a CI script asserting every fileReplacements replace/with path exists relative to workspaceRoot."],"tags":["angular-cli","file-replacements","missing-file","configuration"],"backgroundTag":"missing-file-replacement","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}