@agm/core 模块在 angular 中给出错误 7 'ɵɵdefineInjectable' was not found in '@angular/core'

@agm/core modules are giving error in angular 7 'ɵɵdefineInjectable' was not found in '@angular/core'

我正在使用@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", "时髦信息-window": "^1.1.1", "ngx-bootstrap-滑块": "^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模块不支持angular7吗?如何使这些工作。我只需要使用 angular 7

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

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

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

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