无法使用ANT Design NG-ZORRO;在“ @ angular / core”中找不到导出“ɵɵinject”

时间:2019-09-11 09:45:15

标签: angular ng-zorro-antd

我尝试在我的项目中使用ANT Design NG-ZORRO库。但是,当我编译代码时,会收到以下警告:

WARNING in ./node_modules/ng-zorro-antd/fesm5/ng-zorro-antd-core.js 2294:66-84
"export 'ɵɵdefineInjectable' was not found in '@angular/core'

这会导致运行时错误:

Uncaught TypeError: Object(...) is not a function
    at ng-zorro-antd-core.js:2294
    at Module../node_modules/ng-zorro-antd/fesm5/ng-zorro-antd-core.js (ng-zorro-antd-core.js:2296)

我在互联网上搜索并尝试了所涉及软件包的各种版本组合。但是无法使其正常工作。

package.json的摘录:

"dependencies": {
    "@angular/animations": "^7.2.15",
    "@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/platform-browser": "^7.2.13",
    "@angular/platform-browser-dynamic": "^7.2.13",
    "@angular/platform-server": "^7.2.13",
    "@angular/router": "^7.2.13",
    "@aspnet/signalr": "^1.1.4",
    "@fortawesome/angular-fontawesome": "^0.3.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.22",
    "@fortawesome/free-regular-svg-icons": "^5.10.2",
    "@fortawesome/free-solid-svg-icons": "^5.10.2",
    "@nguniversal/module-map-ngfactory-loader": "^7.1.1",
    "ajv": "^6.10.0",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^4.3.1",
    "core-js": "2.6.5",
    "jquery": "^3.4.0",
    "messagepack": "^1.1.10",
    "ng-zorro-antd": "^8.3.0",
    "popper.js": "^1.15.0",
    "rtcp-web-viewer": "^2.0.3",
    "rxjs": "^6.5.3",
    "zone.js": "^0.9.1"
  }

要使这些软件包正常工作,我需要怎么做才能解决这些警告和错误?

1 个答案:

答案 0 :(得分:1)

这是因为您使用的ng-zorro-antd库版本与使用的Angular库不兼容。

版本8.0.0ng-zorro-antd库中的最高版本要求您更新Angular依赖项以使用版本8.0.0及更高版本(有关更多信息,请参见release notes for version 8.0.0)。 / p>

因此,您必须:

  • 将Angular依赖项更新到版本8及更高版本(有关更新方法的详细信息,请参见Angular Update Guide),或

  • ng-zorro-antd库降级到较旧的版本(在这种情况下,您应该使用最新的7.x.x版本-7.5.1