How to replace buildTarget in angular 17 instead of browserTarget in version 16?

2.7k Views Asked by At

I get error when I was run angular like below:

   Error: Schema validation failed with the following errors:
  Data path "" must have required property 'browserTarget'.

enter image description here

enter image description here

because I am using angular Cli version 17 then my angular.json it has some difference from Angular 16 So I changed buildTarget to browserTarget but I got this error.

This version of CLI is only compatible with Angular versions ^16.0.0,

but Angular version 17.0.8 was found instead.

This is my angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "issue-tracker": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "standalone": false
        },
        "@schematics/angular:directive": {
          "standalone": false
        },
        "@schematics/angular:pipe": {
          "standalone": false
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "outputPath": "dist/issue-tracker",
            "index": "src/index.html",
            "browser": "src/main.ts",
            "polyfills": ["zone.js"],
            "tsConfig": "tsconfig.app.json",
            "assets": ["src/favicon.ico", "src/assets"],
            "styles": ["node_module/@clr/ui/clr-ui.min.css", "src/styles.css"],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "buildTarget": "issue-tracker:build:production"
            },
            "development": {
              "buildTarget": "issue-tracker:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "buildTarget": "issue-tracker:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "polyfills": ["zone.js", "zone.js/testing"],
            "tsConfig": "tsconfig.spec.json",
            "assets": ["src/favicon.ico", "src/assets"],
            "styles": ["src/styles.css"],
            "scripts": []
          }
        }
      }
    }
  }
}

and this is my package.json:

    {
  "name": "issue-tracker",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^17.0.0",
    "@angular/common": "^17.0.8",
    "@angular/compiler": "^17.0.0",
    "@angular/core": "^17.0.0",
    "@angular/forms": "^17.0.0",
    "@angular/platform-browser": "^17.0.0",
    "@angular/platform-browser-dynamic": "^17.0.0",
    "@angular/router": "^17.0.0",
    "@cds/core": "^6.9.1",
    "@clr/angular": "^16.2.0",
    "@clr/ui": "^16.2.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.2.11",
    "@angular/cli": "^17.0.7",
    "@angular/compiler-cli": "^17.0.0",
    "@types/jasmine": "~5.1.0",
    "jasmine-core": "~5.1.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.2.2"
  }
}

is anyone idea to fix this error in angular 17?

2

There are 2 best solutions below

0
On

After few hours I find out the answer to fix this bug I am just use these two commands:

ng update @angular/cdk
ng update @angular/core

and my project run with out any issue.

0
On

I also faced the same issue while running the npm start

Error: Schema validation failed with the following errors: Data path "" must have required property 'browserTarget'.

Then tried to build the project using ng build, and now I got

This version of CLI is only compatible with Angular versions ^16.0.0, but Angular version 17.0.8 was found instead.

Please visit the link below to find instructions on how to update Angular. https://update.angular.io/ Blockquote

Issue was @angular-devkit/build-angular:^16.2.11 in package.json

Solution: Update the above dependency with the latest version using ng update @angular-devkit/build-angular