【问题标题】:“.builders['browser']” should have required property 'class'“.builders['browser']”应该有必需的属性'class'
【发布时间】:2019-11-25 08:53:04
【问题描述】:

使用 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

【问题讨论】:

  • 您是否尝试将 @angular/core 更新到 ~7.0.0 ?它对我有用。

标签: angular webpack webpack-dev-server


【解决方案1】:

就我而言,这是一个依赖版本问题。
我更改了以下依赖项版本:

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

到:

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

【讨论】:

  • 是的,正确的。我有这个版本为8.x.x 的库,我使用的是Angular 版本7.x.x。我卸载并再次安装了版本为7.x.x 的库。有用! npm uninstall -D @angular-builders/custom-webpacknpm i -D @angular-builders/custom-webpack@7
【解决方案2】:

我遇到了同样的错误。但就我而言,我需要使用"@angular-builders/custom-webpack:dev-server" builder,它似乎仅适用于 Angular CLI 8+。 IE。我必须先升级到 Angular 8。

您的情况应该更简单,因为您只使用"custom-webpack:browser",即available in version 7

因此请尝试以下操作:更改 "@angular-builders/custom-webpack" 的版本和 "@angular-builders/dev-server"package.json^7.3.0(或更高版本,但不是版本 8)中,运行 npm installyarn 并再次尝试构建。

来源:https://github.com/manfredsteyer/ngx-build-plus/issues/109

【讨论】:

    【解决方案3】:

    我认为你需要改变这一行

     "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"
    }
    

    【讨论】:

    • 替换构建器后服务器运行成功,但是当我想浏览我的项目时出现以下错误:Uncaught ReferenceError: node_process is not defined。正如我所说,该项目长期以来一直运行良好。
    猜你喜欢
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 2021-06-19
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    相关资源
    最近更新 更多