Skip to content

output-hashing in angular 17 (prerender mode) does not work #27349

@darushHamidi

Description

@darushHamidi

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

Yes

Description

I have a project that upgraded to Angular 17. Now I want to build the project in prerender mode. To do this, I'm using the following command (the project name is 'suproject'):

ng run suproject:prerender
The problem is, how can I enable --output-hashing? I've tried the following two methods and neither worked:

method 1:

ng run suproject:prerender --output-hashing=all

method 2:(in angular.json)

architect => build => options => "outputHashing": "all",
or
architect => build => configurations => production => "outputHashing": "all",

my angualr.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "suproject": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "rj",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/suproject/browser",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": [
              "zone.js"
            ],
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/xxxx.txt",
              "src/assets",
              "src/sitemap.xml",
              "src/robots.txt",
              "src/nginx.conf",
              "src/manifest.json",
              "src/manifest.webmanifest"
            ],
            "allowedCommonJsDependencies": [
              "pdfjs-dist/build/pdf",
              "pdfjs-dist/web/pdf_viewer",
              "lodash.clonedeep",
              "flat"
            ],
            "styles": [
              {
                "input": "src/assets/css/bootstrap.rtl.min.css",
                "inject": true
              },
              {
                "input": "src/assets/css/toastr.css",
                "inject": true
              },
              {
                "input": "node_modules/@ng-select/ng-select/themes/default.theme.css",
                "inject": true
              },
              {
                "input": "src/assets/styles/ng-select.scss",
                "inject": true
              },
              {
                "input": "node_modules/ngx-spinner/animations/ball-scale-multiple.css",
                "inject": true
              },
              {
                "input": "src/styles.scss",
                "inject": true
              }
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/assets/styles"
              ]
            },
            "scripts": [],
            "serviceWorker": true,
            "ngswConfigPath": "ngsw-config.json"
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "300kb",
                  "maximumError": "600kb"
                }
              ],
              "outputHashing": "all",
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "buildTarget": "suproject:build:production"
            },
            "development": {
              "buildTarget": "suproject:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "buildTarget": "suproject:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": [
              "zone.js",
              "zone.js/testing"
            ],
            "tsConfig": "tsconfig.spec.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/assets/images/logo/favicon/favicon.ico",
              "src/assets",
              "src/manifest.webmanifest",
              "src/manifest.webmanifest"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/suproject/server",
            "main": "server.ts",
            "externalDependencies": [
              "canvas"
            ],
            "tsConfig": "tsconfig.server.json",
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/assets/styles"
              ]
            },
            "inlineStyleLanguage": "scss"
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "sourceMap": true,
              "extractLicenses": false,
              "vendorChunk": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve-ssr": {
          "builder": "@angular-devkit/build-angular:ssr-dev-server",
          "configurations": {
            "development": {
              "browserTarget": "suproject:build:development",
              "serverTarget": "suproject:server:development"
            },
            "production": {
              "browserTarget": "suproject:build:production",
              "serverTarget": "suproject:server:production"
            }
          },
          "defaultConfiguration": "development"
        },
        "prerender": {
          "builder": "@angular-devkit/build-angular:prerender",
          "options": {
            "routesFile": "./src/pre-render-routes.txt",
            "discoverRoutes": false
          },
          "configurations": {
            "production": {
              "browserTarget": "suproject:build:production",
              "serverTarget": "suproject:server:production"
            },
            "development": {
              "browserTarget": "suproject:build:development",
              "serverTarget": "suproject:server:development"
            }
          },
          "defaultConfiguration": "production"
        }
      }
    }
  },
  "cli": {
    "analytics": false
  }
}

my package.json:

{
  "name": "suproject",
  "version": "1.0.0",
  "scripts": {
    "ng": "ng",
    "transloco:optimize": "transloco-optimize dist/suproject/browser/assets/i18n",
    "postbuild": "gulp COMPRESS_JS_FILE",
    "start:dev": "ng serve --port=4200",
    "start": "http-server -a 0.0.0.0 -p 4200 -c-1 dist/suproject/browser",
    "build:dev": "ng build --configuration=production && npm run transloco:optimize",
    "watch": "ng build --watch --configuration=development",
    "test": "ng test",
    "docker:build": "docker build -t suproject .",
    "docker:run": "docker run --rm -it -p 4200:80 suproject",
    "build": "ng run suproject:prerender && npm run transloco:optimize"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^17.1.2",
    "@angular/cdk": "^17.1.2",
    "@angular/common": "^17.1.2",
    "@angular/compiler": "^17.1.2",
    "@angular/core": "^17.1.2",
    "@angular/forms": "^17.1.2",
    "@angular/localize": "^17.1.2",
    "@angular/platform-browser": "^17.1.2",
    "@angular/platform-browser-dynamic": "^17.1.2",
    "@angular/platform-server": "^17.1.2",
    "@angular/router": "^17.1.2",
    "@angular/service-worker": "^17.1.2",
    "@angular/ssr": "^17.1.2",
    "@ng-bootstrap/ng-bootstrap": "^16.0.0",
    "@ng-select/ng-select": "^12.0.7",
    "@ngneat/transloco": "^6.0.4",
    "@popperjs/core": "^2.11.8",
    "@progress/kendo-file-saver": "^1.1.1",
    "bootstrap": "^5.3.2",
    "chart.js": "^4.4.1",
    "ckeditor4-angular": "^4.0.1",
    "express": "^4.18.2",
    "global": "^4.4.0",
    "http-server": "^14.1.1",
    "jwt-decode": "^4.0.0",
    "lodash": "^4.17.21",
    "lodash.clonedeep": "^4.5.0",
    "ng-circle-progress": "^1.7.1",
    "ng-recaptcha": "^13.2.1",
    "ng2-pdf-viewer": "^10.0.0",
    "ngx-clipboard": "^16.0.0",
    "ngx-pagination": "^6.0.3",
    "ngx-progressbar": "^11.1.0",
    "ngx-spinner": "^16.0.2",
    "ngx-toastr": "^18.0.0",
    "persian-utilities": "^1.1.1",
    "pretty-print-json": "^3.0.0",
    "rxjs": "~7.8.1",
    "ssr-window": "^4.0.2",
    "tslib": "^2.6.2",
    "zone.js": "~0.14.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^17.1.2",
    "@angular/cli": "^17.1.2",
    "@angular/compiler-cli": "^17.1.2",
    "@ngneat/transloco-optimize": "5.0.3",
    "@types/ckeditor": "^4.9.10",
    "@types/express": "^4.17.21",
    "@types/jasmine": "~5.1.4",
    "@types/node": "^20.11.16",
    "browser-sync": "^3.0.2",
    "gulp": "^4.0.2",
    "gulp-gzip": "^1.4.2",
    "jasmine-core": "~5.1.1",
    "karma": "~6.4.2",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.1",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.3.3"
  }
}

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI:17.1.2
Node:20.11.1

Package Manager:NPM 10.2.4
OS: Windows 11

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: repro stepsWe cannot reproduce the issue with the information given

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions