Index.html generation failed Angular 16

927 views Asked by At

I have migrated Angular from 15 to 16 but when I try to build the project it throws an error:

Index html failed

angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "cc-front-end": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "hammerjs",
              "moment-timezone",
              "ng-click-outside",
              "snazzy-info-window",
              "rxjs",
              "jsona",
              "tsbase",
              "@agm/snazzy-info-window"
            ],
            "baseHref": "/themes/custom/cc_theme/cc-front-end/dist/",
            "outputPath": "dist",
            "aot": true,
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/images"
            ],
            "styles": [
              "src/styles.scss",
              "node_modules/ngx-toastr/toastr.css",
              "./node_modules/tippy.js/dist/tippy.css",
              "./node_modules/tippy.js/animations/scale.css"
            ],
            "scripts": [
              "node_modules/hammerjs/hammer.min.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": false,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "cc-front-end:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "cc-front-end:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "cc-front-end:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "karmaConfig": "./karma.conf.js",
            "polyfills": [
              "src/polyfills.ts",
              "zone.js/testing"
            ],
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/hammerjs/hammer.min.js"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/images"
            ],
            "include": [
              "**/*.spec.ts"
            ]
          }
        },
        "lint": {
          "builder": "@angular-eslint/builder:lint",
          "options": {
            "lintFilePatterns": [
              "src/**/*.ts",
              "src/**/*.html"
            ]
          }
        }
      }
    },
    "cc-front-end-e2e": {
      "root": "e2e",
      "sourceRoot": "e2e",
      "projectType": "application",
      "targets": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "cc-front-end:serve"
          }
        }
      }
    }
  },
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "cc",
      "style": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "cc"
    },
    "@angular-eslint/schematics:application": {
      "setParserOptionsProject": true
    },
    "@angular-eslint/schematics:library": {
      "setParserOptionsProject": true
    }
  },
  "cli": {
    "analytics": false,
    "cache": {
      "enabled": false
    }
  }
}

Is there any way to find the reason, why index.html is not generated?

ng build output:

ng build

2

There are 2 answers

12
Chetan Baghel On

try ng s --prod to debug,

There must be some error while building

3
MGX On

I faced this issue before, and it was because of a corporate proxy.

From what I gathered, it looks like Node is performing some background HTTP task (like downloading something), and when behind a corporate proxy, it can fail, and fail the index generation.

Try exiting your proxy or VPN, see if the issue persists.

If you need to keep using your proxy/VPN and build your app, you will need to add your Nexus/Artifactory/NPM repo in your project with a .npmrc file.