0

我正在使用 @agm/core 库和 Angular 7 中的几个包。但我收到错误:

WARNING in ./node_modules/@agm/core/fesm5/agm-core.js 4538:34-52
"export 'ɵɵdefineInjectable' was not found in '@angular/core'

WARNING in ./node_modules/ngx-bootstrap-slider/fesm5/ngx-bootstrap-slider.js 7:38-56
"export 'ɵɵdefineInjectable' was not found in '@angular/core'

WARNING in ./node_modules/@agm/core/fesm5/agm-core.js 4538:120-128
"export 'ɵɵinject' was not found in '@angular/core'

我的 package.json

{
  "name": "angular-registration-login-example",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0",
    "@agm/snazzy-info-window": "^1.0.0",
    "@angular/animations": "~7.0.0",
    "@angular/cdk": "^7.0.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/material": "^7.0.0",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "@ng-bootstrap/ng-bootstrap": "^4.2.1",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "core-js": "^2.5.4",
    "igniteui-angular": "^7.0.0",
    "ng-multiselect-dropdown": "^0.2.4",
    "ngx-bootstrap-slider": "^1.8.0",
    "ngx-loading": "^3.0.0",
    "ngx-mask": "^8.0.5",
    "rxjs": "~6.3.3",
    "s": "^1.0.0",
    "snazzy-info-window": "^1.1.1",
    "web-animations-js": "^2.3.1",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.3",
    "@angular/cli": "~7.0.3",
    "@angular/compiler-cli": "^7.2.6",
    "@angular/language-service": "~7.0.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  }
}

根据测试导致问题的软件包是:“@agm/core”:“^1.0.0”、“@agm/snazzy-info-window”:“^1.0.0”、“snazzy-info-window ": "^1.1.1", "ngx-bootstrap-slider": "^1.8.0",

在控制台中它给出了这个错误:

ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at ngx-bootstrap-slider.js:7
    at Module../node_modules/ngx-bootstrap-slider/fesm5/ngx-bootstrap-slider.js (ngx-bootstrap-slider.js:15)
    at __webpack_require__ (bootstrap:83)
    at Module../src/app/shared/app-shared.module.ts (ngx-bootstrap-slider.js:485)
    at __webpack_require__ (bootstrap:83)
    at Module../src/app/theme/theme.module.ts (theme.component.ts:8)
    at __webpack_require__ (bootstrap:83)
    at $_lazy_route_resource lazy namespace object:31
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Object.onInvoke (core.js:14060)
    at resolvePromise (zone.js:831)
    at resolvePromise (zone.js:788)
    at zone.js:892
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:14051)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601)

功能模块中的用法:

@NgModule({
  imports: [
    AppSharedModule,
    SupervisorRoutingModule,
    IgxSliderModule,
    NgMultiSelectDropDownModule.forRoot(),
    AgmCoreModule.forRoot({
      apiKey: "AIzaSyCLXtOnKhBDBGmoqSnfhujdFT2Zmj2r8A"
    }),
    AgmSnazzyInfoWindowModule
  ],
  exports: [],
  declarations: [AdminComponent, ProfileComponent, ConfigurationComponent],
  providers: [],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AdminModule { }

这些版本的 agm 模块不支持 angular 7 吗?如何使这些工作。我只需要使用 angular 7

4

2 回答 2

1

是的,最新版本的@agm/core应该可以与 Angular9/10 一起使用。似乎可以与 Angular7 一起使用的版本是1.0.0-beta.7。首先你应该卸载当前版本的包然后运行npm i @agm/core@1.0.0-beta.7

于 2021-02-04T14:50:18.017 回答
0

devoto13很好地解释了这个问题背后的根本原因。

  • 这个问题的原因是 Angular 6 或 7(不记得确切)在为库(已发布到 NPM)生成的代码中使用了 ɵɵdefineInjectable 作为可摇树的提供程序。然后 Angular 8 将此属性重命名为 defineInjectable 并使用 tree-shakable 提供程序破坏了所有库。然后库被改编并发布了新版本,其中生成的代码使用了defineInjectable。然后 Angular 认为它不够有趣,将 defineInjectable 替换为 ɵɵdefineInjectable 并再次使用 tree-shakable 提供程序破坏了所有库。
  • 由于这种来回重命名,您必须使用特定版本的库和特定版本的 Angular,以确保库所期望的符号实际上存在于 Angular 包中。希望这能解释问题的根本原因。

基本上我们需要看看包是什么时候开发的。在这种情况下,角度 7 大约在 2 年前发布。所以我们需要安装 2 年前发布的软件包版本。这就是如何避免这个问题..

于 2021-02-08T07:00:28.593 回答