从Angular 5.2升级到7.2后出现错误

时间:2019-04-22 13:36:34

标签: angular upgrade

最近,我们已按照https://update.angular.io/

的步骤将角度从5.2升级到7.2

此后,当我们从终端启动npm并尝试使用ui时,我们在浏览器控制台中遇到以下错误,

compiler.js:2430 Uncaught Error: Can't resolve all parameters for ApplicationModule: (?).
    at syntaxError (compiler.js:2430)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getDependenciesMetadata (compiler.js:18984)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getTypeMetadata (compiler.js:18877)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (compiler.js:18745)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleSummary (compiler.js:18555)
    at compiler.js:18669
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (compiler.js:18657)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleSummary (compiler.js:18555)
    at compiler.js:18642

下面是我们所拥有的一些工件,

package.json

{
  "name": "angular-poc",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "buildLocal": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "7.2.13",
    "@angular/cdk": "7.3.7",
    "@angular/common": "7.2.13",
    "@angular/compiler": "7.2.13",
    "@angular/core": "7.2.13",
    "@angular/forms": "7.2.13",
    "@angular/http": "7.2.13",
    "@angular/material": "7.3.7",
    "@angular/platform-browser": "7.2.13",
    "@angular/platform-browser-dynamic": "7.2.13",
    "@angular/router": "7.2.13",
    "@ngx-progressbar/core": "5.3.2",
    "@ngx-progressbar/http": "5.3.2",
    "@nicky-lenaers/ngx-scroll-to": "2.0.0",
    "@types/lodash": "4.14.123",
    "ag-grid": "~17.1.1",
    "ag-grid-angular": "~17.1.0",
    "ag-grid-enterprise": "~17.1.1",
    "angular-tabs-component": "1.0.6",
    "classlist.js": "1.1.20150312",
    "core-js": "^3.0.1",
    "font-awesome": "4.7.0",
    "keycloak-angular": "6.1.0",
    "ng-animate": "0.3.4",
    "ng-pick-datetime": "7.0.0",
    "ng2-scroll-to-el": "1.2.1",
    "ngx-toastr": "10.0.2",
    "reflect-metadata": "0.1.12",
    "rxjs": "6.4.0",
    "tslib": "1.9.3",
    "web-animations-js": "2.3.1",
    "zone.js": "0.9.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.13.8",
    "@angular/cli": "^7.3.8",
    "@angular/compiler-cli": "7.2.13",
    "@angular/language-service": "7.2.13",
    "@types/jasmine": "3.3.12",
    "@types/jasminewd2": "2.0.6",
    "@types/node": "11.13.5",
    "codelyzer": "5.0.0",
    "jasmine-core": "3.4.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "4.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-coverage-istanbul-reporter": "2.0.5",
    "karma-jasmine": "2.0.1",
    "karma-jasmine-html-reporter": "1.4.0",
    "protractor": "5.4.2",
    "ts-node": "8.1.0",
    "tslint": "~5.9.1",
    "typescript": "3.2.4"
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "paths": {
      "core-js/es6/*": [
        "node_modules/core-js/es/*"
      ],
      "core-js/es7/*": [
        "node_modules/core-js/es/*"
      ]
    },
    "importHelpers": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "module": "es2015",
    "baseUrl": "./"
  }
}

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "paths": {
      "core-js/es6/*": [
        "../node_modules/core-js/es/*"
      ],
      "core-js/es7/*": [
        "../node_modules/core-js/es/*"
      ]
    },
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

polyfills.ts

/**
 * This file includes polyfills needed by Angular and is loaded before the app.
 * You can add your own extra polyfills to this file.
 *
 * This file is divided into 2 sections:
 *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
 *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
 *      file.
 *
 * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
 * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es7/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es7/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js';  // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
//import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

/**
 * Required to support Web Animations `@angular/platform-browser/animations`.
 * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
 **/
import 'web-animations-js';  // Run `npm install --save web-animations-js`.



/***************************************************************************************************
 * Zone JS is required by default for Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.



/***************************************************************************************************
 * APPLICATION IMPORTS
 */

1 个答案:

答案 0 :(得分:0)

core-js从2.6.9升级到3.1.4后,我遇到了同样的错误…… 以下对Angular问题26128的回答给了我一个提示。

我向polyfill.ts添加了以下行,从而解决了该问题:

import 'core-js/proposals/reflect-metadata';

或者,您可以使用reflect-metadata

npm install reflect-metadata并将import 'reflect-metadata/Reflect'; 添加到polyfill.ts