Skip to content

Angular.json's fileReplacements no longer accept .html replacements in Angular 11 #19390

@ChristopherHoffman

Description

@ChristopherHoffman

🐞 bug report

Affected Package

The issue is caused by package @angular/cli: "~11.0.1",

Is this a regression?

Yes, the previous version in which this bug was not present was "@angular/cli": "^10.2.0",

Description

Angular 11's angular.json no longer allows fileReplacements with .html files, as the @angular/cli schema says .html files are invalid. ng build --prod also errors when trying to run with html in fileReplacements

angular.json

...
      "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                },
                {
                  "replace": "src/index.html",
                  "with": "src/index.prod.html"
                }
              ],
...

Running ng build --prod exits with error:

> ng build --prod

Schema validation failed with the following errors:
  Data path ".fileReplacements[1]" should NOT have additional properties(replace).
  Data path ".fileReplacements[1].replace" should match pattern "\.([cm]?j|t)sx?$".
  Data path ".fileReplacements[1]" should match exactly one schema in oneOf.

vscode also gives a linting warning with String does not match the pattern of "\.([cm]?j|t)sx?$". for the two .html lines.

Expectation

Expect that .html fileReplacements replacements are allowed, since it is useful to have different meta tags and other analytics scripts stored in the index.html file for different build configurations.

🔬 Minimal Reproduction

Example repo here: https://github.com/ChristopherHoffman/Angular11-Html-File-Replacement-Broken/tags

Tag "Working" is a fresh app using the Angular 10 cli, with just a index.prod.html to the angular.json's production configuration. ng build --prod works as expected.

Tag "Broken" is just after updating to Angular 11, and ng build --prod no longer works because of that .html.

🔥 Exception or Error


> ng build --prod

Schema validation failed with the following errors:
  Data path ".fileReplacements[1]" should NOT have additional properties(replace).
  Data path ".fileReplacements[1].replace" should match pattern "\.([cm]?j|t)sx?$".
  Data path ".fileReplacements[1]" should match exactly one schema in oneOf.

🌍 Your Environment

Angular Version:


Angular CLI: 11.0.1
Node: 14.5.0
OS: win32 x64

Angular: 11.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.1
@angular-devkit/build-angular   0.1100.1
@angular-devkit/core            11.0.1
@angular-devkit/schematics      11.0.1
@angular/cli                    11.0.1
@angular/flex-layout            11.0.0-beta.33
@schematics/angular             11.0.1
@schematics/update              0.1100.1
rxjs                            6.6.3
typescript                      4.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions