从 Angular 9.17 升级到 9.19 后无法构建

Unable to build since upgrading from Angular 9.17 to 9.19

我从 Angular 9.17 升级到 9.19,现在 ng 构建失败并出现以下错误,抱怨 @types/node 和 zone.js 中的变量声明:

node_modules/@types/node/ts3.5/globals.global.d.ts:1:13 中的错误 - 错误 TS2403:后续变量声明必须具有相同的类型。变量 'global' 必须是 'Global' 类型,但这里的类型是 'Global & typeof globalThis'.

1 声明 var global: NodeJS.Global & typeof globalThis; ~~~~~~

node_modules/zone.js/dist/zone.js.d.ts:600:13 600 声明 var 全局:NodeJS.Global; ~~~~~~ 'global'也在这里声明。

升级前运行良好,现在无法构建。这是唯一的变化。

请帮忙

我的package.json

{
  "name": "myapp",
  "private": true,
  "version": "1.0.0",
  "scripts": {
    "ng": "ng",
    "start": "echo hello && ng serve --live-reload=false",
    "build": "node --max_old_space_size=4096 ng build",
    "build:ssr": "ng run MIC:server:dev",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "postcss": {},
  "dependencies": {
    "@angular-devkit/schematics": "9.1.7",
    "@angular/animations": "9.1.9",
    "@angular/cdk": "9.2.4",
    "@angular/common": "9.1.9",
    "@angular/compiler": "9.1.9",
    "@angular/core": "9.1.9",
    "@angular/flex-layout": "9.0.0-beta.31",
    "@angular/forms": "9.1.9",
    "@angular/localize": "9.1.9",
    "@angular/material": "9.2.4",
    "@angular/material-moment-adapter": "9.2.4",
    "@angular/platform-browser": "9.1.9",
    "@angular/platform-browser-dynamic": "9.1.9",
    "@angular/platform-server": "9.1.9",
    "@angular/router": "9.1.9",
    "@fortawesome/angular-fontawesome": "0.6.1",
    "@fortawesome/fontawesome-svg-core": "1.2.28",
    "@fortawesome/free-regular-svg-icons": "5.13.0",
    "@fortawesome/free-solid-svg-icons": "5.13.0",
    "@microsoft/signalr": "3.1.4",
    "@microsoft/signalr-protocol-msgpack": "3.1.4",
    "@ng-bootstrap/ng-bootstrap": "6.1.0",
    "@ng-select/ng-select": "4.0.0",
    "@nguniversal/module-map-ngfactory-loader": "9.0.0-next.9",
    "@swimlane/ngx-charts": "14.0.0",
    "@syncfusion/ej2-angular-buttons": "18.1.52",
    "@syncfusion/ej2-angular-calendars": "18.1.53",
    "@syncfusion/ej2-angular-dropdowns": "18.1.54",
    "@syncfusion/ej2-angular-splitbuttons": "18.1.52",
    "angular-dual-listbox": "5.0.1",
    "angular2-notifications": "9.0.0",
    "aspnet-prerendering": "3.0.1",
    "bootstrap": "4.5.0",
    "classlist.js": "1.1.20150312",
    "core-js": "3.6.5",
    "date-fns": "2.14.0",
    "hammer-timejs": "1.1.0",
    "hammerjs": "2.0.8",
    "hash-sum": "2.0.0",
    "immutable": "4.0.0-rc.12",
    "intl": "1.2.5",
    "jquery": "3.5.1",
    "jwt-decode": "2.2.0",
    "material-design-icons": "3.0.1",
    "moment": "2.26.0",
    "ng-validator": "2.0.0",
    "ngx-material-timepicker": "5.5.2",
    "ngx-print": "1.2.0-beta.4",
    "oidc-client": "1.10.1",
    "popper.js": "1.16.1",
    "primeicons": "3.0.0",
    "primeng": "9.1.0",
    "rxjs": "6.5.5",
    "tippy.js": "6.2.3",
    "tslib": "2.0.0",
    "web-animations-js": "2.3.2",
    "zone.js": "0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.901.7",
    "@angular/cli": "9.1.7",
    "@angular/compiler-cli": "9.1.9",
    "@angular/language-service": "9.1.9",
    "@boldreports/angular-reporting-components": "2.2.32",
    "@boldreports/types": "2.2.32",
    "@intervolga/optimize-cssnano-plugin": "1.0.6",
    "@types/jasmine": "3.5.10",
    "@types/jasminewd2": "2.0.8",
    "@types/jquery": "3.3.38",
    "@types/jwt-decode": "2.2.1",
    "@types/node": "14.0.5",
    "autoprefixer": "9.8.0",
    "codelyzer": "5.2.2",
    "jasmine-core": "3.5.0",
    "jasmine-spec-reporter": "5.0.2",
    "karma": "5.0.7",
    "karma-chrome-launcher": "3.1.0",
    "karma-coverage-istanbul-reporter": "3.0.2",
    "karma-jasmine": "3.1.1",
    "karma-jasmine-html-reporter": "1.5.4",
    "karma-scss-preprocessor": "4.0.0",
    "typescript": "3.8.3",
    "webpack-dev-server": "3.11.0"
  },
  "optionalDependencies": {
    "node-sass": "4.14.1",
    "protractor": "7.0.0",
    "tslint": "6.1.2",
    "ts-node": "8.10.1"
  }
}

看来您需要等待@types/node包的新版本。在这种情况下(目前)降级到 14.0.4 对我有帮助。

npm install @types/node@14.0.4 --saveDev

问题不是来自 @types/node,而是来自 angular 本身的 zone.js 依赖项,Here for the Github related issue

似乎知道您可以将 zone.js 升级到最新版本。 至少v0.11.1

npm i zone.js@latest

但是,请注意 breaking changes 重新升级旧版浏览器,例如 IE11。

然后随时将您的@types/node升级到最新版本

npm i @types/node@latest