Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fullcalendar lib before attempting to import a plugin

I installed FullCalendar 5 in my Angular 9 project

then I get this error in the console of browser and anything appears in the page

vdom.js:3 Uncaught Error: Please import the top-level full calendar lib before attempting to import a plugin.
    at Module../node_modules/@fullcalendar/common/vdom.js (vdom.js:3)
    at __webpack_require__ (bootstrap:79)
    at Module../node_modules/@fullcalendar/common/main.js (main.js:1)
    at __webpack_require__ (bootstrap:79)
    at Module../node_modules/@fullcalendar/daygrid/main.js (main.js:1)
    at __webpack_require__ (bootstrap:79)
    at Module../src/app/demo/demo.component.ts (demo.component.ts:1)
    at __webpack_require__ (bootstrap:79)
    at Module../src/app/Modules/app-routing.module.ts (app-routing.module.ts:1)
    at __webpack_require__ (bootstrap:79)

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FullCalendarModule } from '@fullcalendar/angular'; // for FullCalendar!
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FullCalendarModule // for FullCalendar!
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

import { Component } from '@angular/core';
import dayGridPlugin from '@fullcalendar/daygrid';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  calendarOptions = {
    plugins: [dayGridPlugin],
    initialView: 'dayGridMonth'
  };

}

<full-calendar [options]="calendarOptions"></full-calendar>
like image 762
David Avatar asked Jun 06 '20 23:06

David


3 Answers

For fixing this issue you need to import calendar core library at the top, then you need to initialize core lib in your constructor like this

import { Component } from '@angular/core';
import { Calendar } from '@fullcalendar/core'; // include this line
import dayGridPlugin from '@fullcalendar/daygrid';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  calendarOptions = {
    plugins: [dayGridPlugin],
    initialView: 'dayGridMonth'
  };

 constructor() { 
    const name = Calendar.name; // add this line in your constructor
  }
}
like image 183
rajanbhadauria Avatar answered Oct 23 '22 19:10

rajanbhadauria


There is a better way to deal with this:

Register your plugins in app.modules.ts:

import resourceTimeGridPlugin from '@fullcalendar/resource-timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import bootstrapPlugin from '@fullcalendar/bootstrap';

FullCalendarModule.registerPlugins([ // register FullCalendar plugins
   dayGridPlugin,
   interactionPlugin,
   bootstrapPlugin
]);

...

But in calenderOptions, you have to remove plugin property:

calendarOptions = {
-  plugins: [ dayGridPlugin, interactionPlugin, bootstrapPlugin],
   initialView: 'dayGridMonth',
...
}
like image 2
dduft Avatar answered Oct 23 '22 19:10

dduft


I got the same issue and fixed it by changing the order of the import libraries. What I did was FullCalendarModule library imported before the component in the module.ts like this below:

import { FullCalendarModule } from '@fullcalendar/angular'; 
import dayGridPlugin from '@fullcalendar/daygrid'; 
import interactionPlugin from '@fullcalendar/interaction';
    
import { MycalendarComponent } from './mycalendar/mycalendar.component';
like image 1
Lakshman Avatar answered Oct 23 '22 17:10

Lakshman