3

当我们尝试将 Angular 11 应用程序(单 SPA 微前端)更新到 Angular 12 时,我们面临以下问题。

尝试运行此应用程序时控制台出错:

An unhandled exception occurred: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
  • configuration.output 具有未知属性“chunkLoadingGlobal”。这些属性有效:object { assistantComment?, chunkCallbackName?, chunkFilename?, chunkLoadTimeout?, crossOriginLoading?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTemplate?, devtoolNamespace?, filename?, futureEmitAssetss?, globalObject?, hashDigest?, hashDigestLength?, hashFunction ?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, jsonpScriptType?, library?, libraryExport?, libraryTarget?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine?, webassembly模块文件名?}-> 影响编译输出的选项。outputoptions 告诉 webpack 如何将编译后的文件写入磁盘。有关详细信息,请参阅“C:\Users\newUser\AppData\Local\Temp\ng-UOeNLu\angular-errors.log”。

包.json:

    "name": "my-app",
    "version": "0.0.0",
    "scripts": {
      "ng": "ng",
      "start": "npm run serve",
      "devstart": "ng serve --aot=false",
      "build": "npm run build",
      "test": "ng test"
    },
    "private": true,
    "dependencies": {
      "@angular/animations": "~12.0.5",
      "@angular/cdk": "^12.0.5",
      "@angular/common": "~12.0.5",
      "@angular/compiler": "~12.0.5",
      "@angular/core": "~12.0.5",
      "@angular/forms": "~12.0.5",
      "@angular/material": "^12.0.5",
      "@angular/platform-browser": "~12.0.5",
      "@angular/platform-browser-dynamic": "~12.0.5",
      "@angular/router": "~12.0.5",
      "@material-extended/mde": "^3.0.3",
      "bootstrap-4-grid": "^3.4.0",
      "highcharts": "^8.1.2",
      "html2canvas": "^1.0.0-rc.7",
      "htmldiff-js": "^1.0.5",
      "http-server": "^0.12.3",
      "jquery": "^3.5.1",
      "jspdf": "^2.1.1",
      "mat-table-exporter": "^9.0.0",
      "ngx-mat-select-search": "^2.1.2",
      "ng2-file-upload": "^1.4.0",
      "ngx-matomo": "^0.1.4",
      "ngx-summernote": "^0.8.0",
      "ngx-order-pipe": "^2.0.4",
      "rxjs": "~6.5.4",
      "single-spa": ">=4.0.0",
      "single-spa-angular": "5.0.1",
      "tslib": "^2.0.0",
      "summernote": "^0.8.18",
      "zone.js": "~0.11.4"
    },
    "devDependencies": {
      "@angular-builders/custom-webpack": "9.2.1-beta.0",
      "@angular-devkit/build-angular": "~0.1102.13",
      "@angular/cli": "~12.0.5",
      "@angular/compiler-cli": "~12.0.5",
      "@angular/language-service": "~12.0.5",
      "@types/node": "^12.11.1",
      "@types/jasmine": "~3.6.0",
      "@types/jasminewd2": "~2.0.3",
      "codelyzer": "^6.0.0",
      "jasmine-core": "~3.6.0",
      "jasmine-spec-reporter": "~5.0.0",
      "karma": "~5.0.0",
      "karma-chrome-launcher": "~3.1.0",
      "karma-coverage-istanbul-reporter": "~3.0.2",
      "karma-jasmine": "~4.0.0",
      "karma-jasmine-html-reporter": "^1.5.0",
      "protractor": "~7.0.0",
      "ts-node": "~8.3.0",
      "tslint": "~6.1.0",
      "typescript": "~4.2.4"
    }
  }

角.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-app": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "outputPath": "dist/my-app",
            "index": "src/index.html",
            "main": "src/main.single-spa.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "./node_modules/bootstrap-4-grid/scss/grid.scss",
              "src/styles.scss",
              "node_modules/summernote/dist/summernote-lite.min.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/summernote/dist/summernote-lite.min.js"
            ],
            "customWebpackConfig": {
              "path": "extra-webpack.config.js",
              "libraryName": "my-app",
              "libraryTarget": "umd"
            }
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "none",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "20kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-builders/custom-webpack:dev-server",
          "options": {
            "browserTarget": "my-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "my-app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "my-app: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": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "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": "my-app:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "my-app:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "my-app",
  "cli": {
    "analytics": false
  }
}```
4

2 回答 2

0

我遇到了同样的问题。更改某些依赖项的版本并devDependenciespackage.json我解决它。

将依赖项更改为具有以下内容:

  • "single-spa": "5.9.3"
  • "single-spa-angular": "5.0.2"

将开发依赖项更改为具有以下内容:

  • "@angular-builders/custom-webpack": "12.1.3"
  • "@angular-devkit/build-angular": "12.2.16"
于 2022-03-01T20:47:50.527 回答
-1

几点建议:

  • 如果您想使用 angular-cli 进行平滑迁移,请摆脱自定义 webpack。
  • 不要使用任何库的beta版本,除非您正在试验或测试它的某些内容。自定义 webpack 构建器的版本是 beta(检查 package.json)。
  • 如果你真的需要一个自定义的 webpack 构建器,那么去官方网站更新你的配置。每次更新 Angular 时更新自定义 webpack 依赖项。
  • 不要手动升级 Angular,而是按照https://update.angular.io/的说明进行操作。的版本@angular-devkit/build-angular似乎不正确。
于 2021-07-01T19:25:22.457 回答