【问题标题】:ERROR in node_modules/ng2-toastr/src/toast-container.component.d.ts(1,48): TS2305- /node_modules/@angular/core/core"' has no exported membernode_modules/ng2-toastr/src/toast-container.component.d.ts(1,48) 中的错误:TS2305-/node_modules/@angular/core/core"' 没有导出成员
【发布时间】:2019-02-02 05:49:54
【问题描述】:

我有最新版本的"rxjs": "^6.0.0"@angular/cli": "~6.0.8" 当我运行ng serve 时,我收到以下编译错误-

ERROR in node_modules/ng2-toastr/src/toast-container.component.d.ts(1,48): 
 /node_modules/@angular/core/core"' has no exported member'AnimationTransitionEvent'.

imported toastermodule in the below format in my app.module.ts
import {ToastrModule} from 'ngx-toastr';

也收到以下错误

error TS2305: Module '"C:/Users/user1/Sublime Text 3/NodeJS/groupchat-application/node_modules/rxjs/Observable"' has no exported member 'Observable'.
node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.
imported as below in  My service.ts
import { Observable, of} from "rxjs"; 

请指导如何进行

【问题讨论】:

  • 你能粘贴编码格式的错误吗?我认为应该尝试 npm install。可能是一些包没有正确安装。
  • ./node_modules/ng2-toastr/src/toast-manager.js 中的错误模块未找到:错误:无法解析 '..\NodeJS\groupchat-application 中的 'rxjs/Subject' \node_modules\ng2-toastr\src' ./node_modules/ng2-toastr/src/toast-container.component.js 中的错误 找不到模块:错误:无法解析 'C:\Users\ 中的 'rxjs/Subject' user1\Sublime Text 3\NodeJS\groupchat-application\node_modules\ng2-toastr\src' ./node_modules/ng2-toastr/src/toast-container.component.js 中的错误模块未找到:错误:无法解析' rxjs/add/operator/first' in '/NodeJS\groupchatapplication\node_modules\ng2-toastr\src'
  • 我添加了 ToastrModule.forRoot() 并编译现在我收到如上的错误

标签: node.js angular rxjs


【解决方案1】:

这个问题是由于 toastr 和动画与您的角度版本的兼容性!

   ngx-toastr   Angular
    6.5.0       4.x
    8.10.2      5.x
    10.1.0      8.x 7.x 6.x
    11.3.3      8.x
    12.1.0      9.x
   current  >= 10.x

为您的情况尝试这些版本:

如果项目中有 toastr 和动画,请先卸载它们,然后运行它们:

npm install ngx-toastr@10.0.4 --save

npm install @angular/animations@8.2.14 --save

【讨论】:

    【解决方案2】:

    您使用“rxjs”:“^6.0.0” 和 ng2-toastr:使用低于 6.0.0 的 rxjs,因此存在兼容性问题。 您有两种选择:

    1. rxjs-compatrxjs 6.0.0

    2. 其他使用 ngx-toasta [link]

    编辑: 由于 angular 的更新和它的依赖不同步,如果你使用 angular material 6+,那么你可以选择@angular/material Snackbar,它与 Angular 的最新版本更好地兼容。

    【讨论】:

    • @SamT 你能详细说明一下吗?
    • 由于 angular 的更新和它的依赖不同步,如果你使用 angular material 6+,那么你可以选择@angular/material Snackbar,它与最新版本的 Angular 兼容。
    【解决方案3】:

    我能够使用

    解决这个问题
            npm install ng6-toastr-notifications --save
    

    有一个很好的文档链接可用。我会为你提供链接

    https://www.npmjs.com/package/ng6-toastr-notifications

    【讨论】:

      【解决方案4】:
      Use **ngx-toastr**
      
      **steps to follow**
      
      Install dependencies 
      
      1)npm install ngx-toastr --save
      2)npm install @angular/animations --save
      
      3)Add CSS to your angular.json file
      "styles": [
        "styles.scss",
        "node_modules/ngx-toastr/toastr.css" // try adding '../' if you're using angular cli before 6
      ]
      
      4)Add toastr module to your app.module.ts
      import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
      import { ToastrModule } from 'ngx-toastr';
      
      @NgModule({
        imports: [BrowserAnimationsModule,
          ToastrModule.forRoot() 
      })
      
      5) Add toastr service to your desired component 
      
      import { ToastrService } from 'ngx-toastr';
      
      @Component({...})
      export class YourComponent {
        constructor(private toastr: ToastrService) {}
      
        showSuccess() {
          this.toastr.success('Hello world!', 'Toastr fun!');
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-04-24
        • 2019-02-02
        • 1970-01-01
        • 2020-06-02
        • 2019-01-17
        • 2020-03-12
        • 1970-01-01
        • 2019-05-10
        • 2018-11-25
        相关资源
        最近更新 更多