flauc / angular2-notifications

A light and easy to use notifications library for Angular.
https://stackblitz.com/edit/angular2-notifications-example
MIT License
746 stars 163 forks source link

bug with 0.5.3 - Error: BrowserModule has already been loaded. #188

Closed htrex closed 6 years ago

htrex commented 7 years ago

On an angular-cli 1.0.0 project using Angular 4.0.1, if I upgrade this package from 0.4.53 to 0.5.3 I'm seeing the following error, changing back package.json to 0.4.53 and npm install again solves the problem.

ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead. Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

LucasBrazi06 commented 7 years ago

Change in app.module from

import { SimpleNotificationsModule } from 'angular2-notifications';

imports:[
    BrowserModule,
    SimpleNotificationsModule.forRoot(),
]

to

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { SimpleNotificationsModule } from 'angular2-notifications';

imports: [
    CommonModule,
    BrowserAnimationsModule,
    SimpleNotificationsModule.forRoot(),
]

I'm still having an issue with my template when trying to use it:

**Error: Template parse errors: 'simple-notifications' is not a known element:

  1. If 'simple-notifications' is an Angular component, then verify that it is part of this module.
  2. If 'simple-notifications' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.**

I tried to import the component without success!

gparonitti commented 7 years ago

@LucasBrazi06 The change you proposed didn't solve the issue, I still receive

Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

When I lazy load any module with SimpleNotificationsModule class enabled.

maxime1992 commented 7 years ago

Same problem here : image

marnickmenting commented 7 years ago

I'm having the same problem in version 0.5.7, using webpack. I tried to fiddle with the imports, but I can't even find an import of BrowserModule anywhere in the repo, only BrowserAnimationsModule. I am just using simple-notifications, no push-notifications.

flauc commented 7 years ago

I don't get it. I don't import BrowserModule anywhere. Do you think BrowserAnimationsModule is what is causing it?

marnickmenting commented 7 years ago

I updated @angular/angular and related libraries to stable version 4.0.3, I was still on a beta version. The BrowserModule error is gone now. I now get

ERROR Error: Uncaught (in promise): Error: Template parse errors:
'simple-notifications' is not a known element

I'm trying to fix it by moving my declarations around.

marnickmenting commented 7 years ago

By trial and error I got it working! Here's what I have now.

In app.module.ts:

import { SimpleNotificationsModule } from 'angular2-notifications';

...

imports: [
        CommonModule,
        SimpleNotificationsModule.forRoot(),

In app.component.ts:

template: '<router-outlet></router-outlet>
<simple-notifications [options]="notificationOptions"></simple-notifications>'

...

export class App {
  notificationsOptions:any = {
    'position': ['top', 'right']
  };

And then in the component where I want to show the notification, for example layout.component.ts:

import { NotificationsService } from 'angular2-notifications';

...

constructor( private _notificationService : NotificationsService ){
    _notificationService.success('hallo', 'hoi');
}
flauc commented 7 years ago

This is great, thank you so much 👍

liymike commented 7 years ago

@flauc After upgrading from 0.4.53 I got this problem too. Below is my solution. I just commented BrowserAnimationsModule in both node_modules/angular2-notifications/dist/src/simple-notifications.module.js and node_modules/angular2-notifications/src/simple-notifications.module.ts.

it works for me now.

I'm using angular4.0.3 and angular2-notifications 0.5.7, and in my app.module.ts I'm using BrowserAnimationsModule .

johnrossell commented 7 years ago

I'm lazy loading modules and am also seeing this issue (ng4.1.0) An official release with removed BrowserAnimationsModule references would be much appreciated. Thanks for all the hard work, great plugin.

flauc commented 6 years ago

This is resolved in the latest release. Please reopen if you are still getting it

duhamaher commented 2 years ago

im still getting this issue