将 Angular 11 应用程序升级到 Angular 12 时面临的问题
Posted
技术标签:
【中文标题】将 Angular 11 应用程序升级到 Angular 12 时面临的问题【英文标题】:Facing issue while upgrading Angular 11 app to Angular 12 【发布时间】:2021-09-06 21:35:26 【问题描述】:当我们尝试将 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?, webassemblyModuleFilename? -> 影响编译输出的选项。 output
选项告诉 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"
Angular.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
```
【问题讨论】:
这个回答***.com/a/42068953/9721056能解决你的问题吗? 你能发布你的 angular.json 和 package.json 吗?您是先升级全局安装,然后在 package.json 所在的项目根目录运行 ng update @angular/core @angular/cli 吗? @cklimowski 我已编辑问题以添加 package.json 和 angular.json 您是否首先使用 npm i -g @angular/cli@12.0.5 升级全局 @angular/cli 安装,然后运行 ng update @angular/core @angular/cli? @cklimowski 是的,我先升级全局 cli,然后运行 ng update 【参考方案1】:一些建议:
如果您想使用 angular-cli 进行平滑迁移,请摆脱自定义 webpack。 请勿使用任何库的 beta 版本,除非您正在试验或测试有关它的内容。自定义 webpack builder 的版本是 beta(检查 package.json)。 如果你真的需要一个自定义的 webpack 构建器然后去官方网站更新你的配置。每次更新 Angular 时更新您的自定义 webpack 依赖项。 不要手动升级 Angular,而是按照https://update.angular.io/ 的说明进行操作。@angular-devkit/build-angular
的版本似乎不正确。
【讨论】:
以上是关于将 Angular 11 应用程序升级到 Angular 12 时面临的问题的主要内容,如果未能解决你的问题,请参考以下文章
将 Angular 11 应用程序升级到 Angular 12 时面临的问题
将 Angular 应用程序从 6 升级到 10 更新后会产生很多错误
编译 Angular 11(从 Angular 9 升级)应用程序时出错
升级到 Angular 11 后获取“必须从注入上下文调用注入()”