Ngx-toastr: Error while running ngx-toastr

Created on 27 Nov 2020  路  5Comments  路  Source: scttcper/ngx-toastr

I am getting following errors :

Error: node_modules/ngx-toastr/toastr/toastr.module.d.ts:4:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (ngx-toastr/toastr/toastr.module) which declares ToastrModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

4 export declare class ToastrModule {

_ANGULAR CLI_

Angular CLI: 11.0.2
Node: 15.2.1
OS: win32 x64

Angular: 11.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.1100.2
@angular-devkit/build-angular 0.1100.2
@angular-devkit/core 11.0.2
@angular-devkit/schematics 11.0.2
@schematics/angular 11.0.2
@schematics/update 0.1100.2
rxjs 6.6.3
typescript 4.0.5

Package.JSON

"dependencies": {
"@angular/animations": "^11.0.2",
"@angular/common": "~11.0.1",
"@angular/compiler": "~11.0.1",
"@angular/core": "~11.0.1",
"@angular/forms": "~11.0.1",
"@angular/platform-browser": "~11.0.1",
"@angular/platform-browser-dynamic": "~11.0.1",
"@angular/router": "~11.0.1",
"bootstrap": "^4.5.3",
"jquery": "^3.5.1",
"ngx-toastr": "^13.1.0",
"popper.js": "^1.16.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
}

Most helpful comment

What you have in app.module.ts? I got the exact same error when I used Visual Studio Code auto-generated import.

import { ToastrModule } from 'ngx-toastr/toastr/toastr.module' //generated by Visual Studio Code, not working;
import { ToastrModule } from 'ngx-toastr'; //Works

All 5 comments

How are you importing in your code

import { ToastrService } from 'ngx-toastr';

constructor(private toastr: ToastrService) {}

showSuccess() {
this.toastr.success('Hello world!', 'Toastr fun!');
}

What you have in app.module.ts? I got the exact same error when I used Visual Studio Code auto-generated import.

import { ToastrModule } from 'ngx-toastr/toastr/toastr.module' //generated by Visual Studio Code, not working;
import { ToastrModule } from 'ngx-toastr'; //Works

For those who have correct imports, just restart your server if you are running using ng serve

Having this error while running in Angular 8

`
ERROR in node_modules/ngx-toastr/portal/portal.d.ts:26:9 - error TS1086: An accessor cannot be declared in an ambient context.

26 get isAttached(): boolean;
~~
node_modules/ngx-toastr/toastr/toast-noanimation.component.d.ts:19:9 - error TS1086: An accessor cannot be declared in an ambient context.

19 get displayStyle(): string;
~~~~
node_modules/ngx-toastr/toastr/toast.component.d.ts:26:9 - error TS1086: An accessor cannot be declared in an ambient context.

26 get displayStyle(): string | undefined;
`

Was this page helpful?
0 / 5 - 0 ratings