web-dev-qa-db-ja.com

「.builders ['browser']」には、必須のプロパティ 'class'が必要です

Npm installを使用して依存関係を正常にインストールした後、サーバーの実行中に次のエラーが発生しました。

Schema validation failed with the following errors: Data path ".builders['browser']" should have required property 'class'.

しばらく検索した後、問題は"@angular-builders/custom-webpack"にあると思います。

プロジェクトは問題なく動作していましたが、誤って削除して再度複製すると、エラーが発生しました。

開発依存関係は次のとおりです。

"devDependencies": {
    "@angular-builders/custom-webpack": "latest",
    "@angular-builders/dev-server": "latest",
    "@angular-devkit/build-angular": "~0.13.6",
    "@angular/cli": "~7.3.6",
    "@angular/compiler-cli": "~7.2.10",
    "@angular/language-service": "~7.2.10",
    "@biesbjerg/ngx-translate-extract": "~2.3.4",
    "@types/jasmine": "~3.3.12",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~11.11.4",
    "codelyzer": "~5.0.0-beta.1",
    "dotenv": "latest",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~2.0.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "~1.4.0",
    "protractor": "~5.4.2",
    "rxjs-tslint": "~0.1.7",
    "ts-node": "~8.0.3",
    "tslint": "~5.14.0",
    "TypeScript": "~3.2.0",
    "webpack": "~4.29.6"
}

そして、これが私のangular.jsonファイルです:

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "iShop": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "app",
            "schematics": {
                "@schematics/angular:component": {
                    "styleext": "scss"
                }
            },
            "architect": {
                "build": {
                    "builder": "@angular-builders/custom-webpack:browser",
                    "options": {
                        "customWebpackConfig": {
                            "path": "extra-webpack.config.js"
                        },
                        "outputPath": "dist",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "tsConfig": "src/tsconfig.app.json",
                        "polyfills": "src/polyfills.ts",
                        "assets": [
                            "src/favicon.ico",
                            "src/Apple-touch-icon.png",
                            "src/robots.txt",
                            "src/manifest.json",
                            "src/assets"
                        ],
                        "styles": [
                            "src/main.scss",
                            "src/assets/css/paymentfont/paymentfont.min.css",
                            "./node_modules/font-awesome/css/font-awesome.css",
                            "./node_modules/@ng-select/ng-select/themes/default.theme.css"
                        ],
                        "scripts": []
                    }
                },
                "serve": {
                    "builder": "@angular-builders/dev-server:generic",
                    "options": {
                        "browserTarget": "iShop:build"
                    },
                    "configurations": {
                        "production": {
                            "browserTarget": "iShop:build:production"
                        }
                    }
                }
            }
        },
        "iShop-e2e": {
            "root": "e2e",
            "projectType": "application",
            "architect": {
                "e2e": {
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": {
                        "protractorConfig": "e2e/protractor.conf.js",
                        "devServerTarget": "iShop:serve"
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": [
                            "e2e/tsconfig.e2e.json"
                        ],
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                }
            }
        }
    },
    "defaultProject": "iShop"
}

そして私のangular CLIバージョンは:7.3.9

5
Ayoub k

私の場合、それは依存バージョンの問題でした。
次の依存関係バージョンを変更しました:

"@angular-builders/custom-webpack": "latest"
"@angular-builders/dev-server": "latest"

に:

"@angular-builders/custom-webpack": "~7.4.3"
"@angular-builders/dev-server": "~7.3.1"
2
Ayoub k

この行を変更する必要があると思います

 "builder": "@angular-builders/custom-webpack:browser"

何かに

"builder": "@angular-devkit/build-angular:browser",

また、package.jsonのcustom-webpack設定を確認してください。ビルダーは角度から来るデフォルトの設定を使用する必要があります

以下は私の設定です

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "angular8": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/angular8",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular8:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "angular8:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "angular8:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "angular8:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "angular8:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "angular8"
}
0
Tony Ngo