Angular11: fileReplacements stopped working after angular update
EwertonLeal opened this issue · 3 comments
Command
build
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
My team and I are updating the Angular version of our app. We were using version 10.2.3 and migrated to 11.2.19 in angular/cli
Before updating, our environments files were replaced by fileReplacements
But now that we've updated them, they no longer work.
Package.json:
"dependencies": { "@amcharts/amcharts4": "^4.10.19", "@angular-devkit/build-angular": "^0.1002.3", "@angular/animations": "^11.2.14", "@angular/cdk": "^9.2.4", "@angular/common": "^11.2.14", "@angular/compiler": "^11.2.14", "@angular/core": "^11.2.14", "@angular/flex-layout": "^9.0.0-beta.31", "@angular/forms": "^11.2.14", "@angular/localize": "^11.2.14", "@angular/material": "^9.2.4", "@angular/platform-browser": "^11.2.14", "@angular/platform-browser-dynamic": "^11.2.14", "@angular/router": "^11.2.14", "@aspnet/signalr": "^3.0.0-preview6.19307.2", //-------------------// }, "devDependencies": { "@angular/cli": "^11.2.19", "@angular/compiler-cli": "^11.2.14", "@angular/language-service": "^11.2.14", "@fortawesome/fontawesome-free": "^5.15.3", "@types/crypto-js": "^3.1.47", "@types/jasmine": "^2.8.17", "@types/jasminewd2": "^2.0.9", "@types/jspdf": "^2.0.0", "@types/node": "^12.20.15", "codelyzer": "^5.1.2", "g": "^2.0.1", "http-server": "^0.12.3", "jasmine-core": "~3.5.0", "jasmine-spec-reporter": "~5.0.0", "karma": "~6.4.3", "karma-chrome-launcher": "~3.1.0", "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "^1.5.0", "protractor": "~7.0.0", "ts-node": "~7.0.0", "tslint": "~6.1.0", "typescript": "~4.0.8", "webpack-bundle-analyzer": "^3.9.0" }
angular.json
`
"configurations": {
"production": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "20kb"
}
],
"fileReplacements": [
{
"replace": "src/assets/environments/environment.json",
"with": "src/assets/environments/environment.prod.json"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"dev": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "20kb"
}
],
"fileReplacements": [
{
"replace": "src/assets/environments/environment.json",
"with": "src/assets/environments/environment.dev.json"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"dev-machine": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "20kb"
}
],
"fileReplacements": [
{
"replace": "src/assets/environments/environment.json",
"with": "src/assets/environments/environment.dev-machine.json"
}
]
},
"design-machine": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "20kb"
}
],
"fileReplacements": [
{
"replace": "src/assets/environments/environment.json",
"with": "src/assets/environments/environment.dev-machine.json"
}
],
"sourceMap": false
}
}
}
Minimal Reproduction
We noticed that when returning @angular-devkit/build-angular to version 0.1002.3, the replace happens again, but if we use the version suggested by the Angular update (version 0.1102.18) it no longer works.
Exception or Error
No response
Your Environment
Angular CLI: 11.2.19
Node: 16.16.0
OS: win32 x64
Angular: 11.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1102.18
@angular-devkit/build-angular 0.1102.18
@angular-devkit/core 11.2.18
@angular-devkit/schematics 11.2.19
@angular/cdk 9.2.4
@angular/cli 11.2.19
@angular/flex-layout 9.0.0-beta.31
@angular/material 9.2.4
@schematics/angular 11.2.19
@schematics/update 0.1102.19
rxjs 6.6.7
typescript 4.0.8
Anything else relevant?
No response
Angular version 11 is not longer under support. Please see: https://angular.io/guide/releases#actively-supported-versions
Angular version 11 is not longer under support. Please see: https://angular.io/guide/releases#actively-supported-versions
Good morning, thank you for responding.
But is there a reason why "fileReplacement" replaces the files below when @angular-devkit/build-angular is in version 0.1002.3 and does not when it is in any version above?
"fileReplacements": [ { "replace": "src/assets/environments/environment.json", "with": "src/assets/environments/environment.dev-machine.json" }
fileReplacements is designed for source files that are part of the TypeScript compilation process. It does not work for replacing arbitrary assets (e.g., images or json files) during the build.