manfredsteyer / ngx-build-plus

Extend the Angular CLI's default build behavior without ejecting, e. g. for Angular Elements
1.19k stars 136 forks source link

Unable to build Angular 17 PWA fails with Data path "/serviceWorker" must be boolean #404

Open jdalysgfy opened 5 months ago

jdalysgfy commented 5 months ago

Describe the bug

I am unable to build an Angular 17 Project after adding @angular/pwa followed by @angular-architects/module-federation.

Running ng build after adding @angular-architects/module-federation results in the below error:

Error: Schema validation failed with the following errors:
  Data path "/serviceWorker" must be boolean.

Error seems to be a result of the serviceWorker field in angular.json now accepting string values.

angular.json (Angular 16)

"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"

angular.json (Angular 17)

"serviceWorker": "ngsw-config.json",

Workaround

Set the serviceWorker value in angular.json back to how it was in Angular 16 PWA:

"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"

How to Reproduce

ng new Angular17Project
ng add @angular/pwa
ng build
ng add @angular-architects/module-federation
ng build

angular.json (Angular 17)

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "Angular17Project": {
            "projectType": "application",
            "schematics": {
                "@schematics/angular:component": {
                    "style": "scss"
                }
            },
            "root": "",
            "sourceRoot": "src",
            "prefix": "app",
            "architect": {
                "build": {
                    "builder": "ngx-build-plus:browser",
                    "options": {
                        "outputPath": "dist/angular17-project",
                        "index": "src/index.html",
                        "polyfills": [
                            "zone.js"
                        ],
                        "tsConfig": "tsconfig.app.json",
                        "inlineStyleLanguage": "scss",
                        "assets": [
                            "src/favicon.ico",
                            "src/assets",
                            "src/manifest.webmanifest"
                        ],
                        "styles": [
                            "src/styles.scss"
                        ],
                        "scripts": [],
                        "main": "src/main.ts",
                        "extraWebpackConfig": "webpack.config.js",
                        "commonChunk": false
                    },
                    "configurations": {
                        "production": {
                            "budgets": [
                                {
                                    "type": "initial",
                                    "maximumWarning": "500kb",
                                    "maximumError": "1mb"
                                },
                                {
                                    "type": "anyComponentStyle",
                                    "maximumWarning": "2kb",
                                    "maximumError": "4kb"
                                }
                            ],
                            "outputHashing": "all",
                            "serviceWorker": "ngsw-config.json",
                            "extraWebpackConfig": "webpack.prod.config.js"
                        },
                        "development": {
                            "optimization": false,
                            "extractLicenses": false,
                            "sourceMap": true
                        }
                    },
                    "defaultConfiguration": "production"
                },
                "serve": {
                    "builder": "ngx-build-plus:dev-server",
                    "configurations": {
                        "production": {
                            "buildTarget": "Angular17Project:build:production",
                            "extraWebpackConfig": "webpack.prod.config.js"
                        },
                        "development": {
                            "buildTarget": "Angular17Project:build:development"
                        }
                    },
                    "defaultConfiguration": "development",
                    "options": {
                        "port": 4201,
                        "publicHost": "http://localhost:4201",
                        "extraWebpackConfig": "webpack.config.js"
                    }
                },
                "extract-i18n": {
                    "builder": "ngx-build-plus:extract-i18n",
                    "options": {
                        "buildTarget": "Angular17Project:build",
                        "extraWebpackConfig": "webpack.config.js"
                    }
                },
                "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "polyfills": [
                            "zone.js",
                            "zone.js/testing"
                        ],
                        "tsConfig": "tsconfig.spec.json",
                        "inlineStyleLanguage": "scss",
                        "assets": [
                            "src/favicon.ico",
                            "src/assets",
                            "src/manifest.webmanifest"
                        ],
                        "styles": [
                            "src/styles.scss"
                        ],
                        "scripts": []
                    }
                }
            }
        }
    }
}

Expected Behaviour

Should build successfully.