微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决@agm/core 模块在 angular 7 中给出错误 'ɵɵdefineInjectable' is 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",

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

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

解决方法

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

,

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?