angular-cli: Index html generation failed on ng build in Angular 12

Bug Report

Affected Package

Not sure which package is causing this error, here are the packages in use

{
  "name": "quiz-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~12.0.0",
    "@angular/cdk": "^12.0.0",
    "@angular/common": "~12.0.0",
    "@angular/compiler": "~12.0.0",
    "@angular/core": "~12.0.0",
    "@angular/flex-layout": "^11.0.0-beta.33",
    "@angular/forms": "~12.0.0",
    "@angular/material": "^12.0.0",
    "@angular/platform-browser": "~12.0.0",
    "@angular/platform-browser-dynamic": "~12.0.0",
    "@angular/router": "~12.0.0",
    "@types/prismjs": "^1.16.5",
    "express": "^4.17.1",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "ngx-cookie-service": "^11.0.2",
    "path": "^0.12.7",
    "perfect-scrollbar": "^1.5.1",
    "prismjs": "^1.23.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.1.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.0.0",
    "@angular/cli": "~12.0.0",
    "@angular/compiler-cli": "~12.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/lodash": "^4.14.169",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.7.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "typescript": "~4.2.3"
  },
  "engines": {
    "node": "14.17.0",
    "npm": "6.14.13"
  }
}

Is this a regression?

Description

While running the build using ng build command, the build fails to generate the Index HTML file with the following error Screenshot 2021-05-15 at 12 46 41 PM

Minimal Reproduction

Check the build log: https://github.com/anuj9196/quiz-app/runs/2589355739?check_suite_focus=true#step:7:56

To reproduce

  • take a clone of the repository
  • Install dependencies npm install
  • Build the project ng build

Exception or Error


✔ Browser application bundle generation complete.
✔ Copying assets complete.
✖ Index html generation failed.
undefined:4:720308: missing '}'

Your Environment

Angular Version:


Angular CLI: 12.0.0
Node: 14.17.0
Package Manager: npm 6.14.13
OS: darwin x64

Angular: 12.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.0
@angular-devkit/build-angular   12.0.0
@angular-devkit/core            12.0.0
@angular-devkit/schematics      12.0.0
@angular/flex-layout            11.0.0-beta.33
@schematics/angular             12.0.0
rxjs                            6.6.7
typescript                      4.2.4

Anything else relevant? Setting "optimization": false in the build > options builds the project file but the build budget size is 2 MB more.

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/quiz-app",
            "optimization": false,
            ...
         }
     }
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 11
  • Comments: 26 (2 by maintainers)

Commits related to this issue

Most upvoted comments

disabling inlineCritical style optimization allows the build to succeed. The following config works for me however I’d like to now exactly why: "optimization": { "scripts": true, "fonts": { "inline": true }, "styles": { "minify": true, "inlineCritical": false } },

@anuj9196,

It appears that in your case the problem is that the CSS optimizer is incorrectly optimising media queries which is causing the CSS parser to fail.

Opening style.css and navigating to the line and column indicated in the error message we find the below which is invalid CSS as the media query has no feature value instead of @media all.

@media{.page-break-after,.page-break-before{display:none}}

Let’s continue tracking this https://github.com/cssnano/cssnano/issues/1105

Likely related to #20760, will need to take a look later to confirm if it’s the same root cause with data URIs.

As a workaround you can disable critical CSS inlining https://angular.io/guide/workspace-config#optimization-configuration.

I agree with @DavidMarquezF , at least leave it opened with the link to cssnano issue…although workaround works, we lose some optimization features with it.

Why is this issue closed? It doesn’t appear to be fixed.

For me it also happens with @media all, it removes the all. However, in the css nano issue https://github.com/cssnano/cssnano/issues/1105#issuecomment-869493549 is said that this is the expected behavior of the tools that angular uses.

Apparently @media without anything behind defaults to @media all, thus it gets removed in order to save space.

@tfrijsewijk @Schiepek Thanks for the tips, I run this issue today and your solution helps me fix the problem.

Hello ! 😃 Somebody could publish a npm version of the lib with the @alan-agius4 fix please ?

this game can be played by two 😃 perhaps we should just open a new issue

@Schiepek your problem looks a bit like mine: background-image with data url to an SVG, but without a <style> element inside the SVG…