When using Angular12 (version 12.0.3) to develop a project, the debugging will run normally, but an error message will appear when calling ng build to publish.
Presented: Index html generation failed. undefined:6:720366 missing '}'
Or: Index html generation failed. undefined:6:720366 missing ':' etc.
The solution is to modify the angular.json configuration file and add an optimization node under the build -> configurations -> production node :
"optimization": {
"scripts": true,
"fonts": {
"inline": true
},
"styles": {
"minify": true,
"inlineCritical": false
}
}
The full node path is:
{
...,
"projects":{
"myapp":{
...,
"architect":{
...,
"build":{
...,
"configurations":{
...,
"production": {
...,
"optimization": {
"scripts": true,
"fonts": {
"inline": true
},
"styles": {
"minify": true,
"inlineCritical": false
}
}
}
},
...
},
...
},
...
}
},
...
}