fullcalendar: "Global CSS cannot be imported from within node_modules." - next.js
Reduced Test Case
next.js example repo - https://github.com/fullcalendar/fullcalendar-example-projects/tree/master/next
Bug Description
I try to use FullCalendar with next.js, so I tried the FullCalendar next.js example repo.
After installing I stumbled on a global css error (Global CSS cannot be imported from within node_modules.) and found out that this CSS issue was the reason for this example repo at all.
Sadly the repo don’t work anymore and produces the same error (again).
https://github.com/fullcalendar/fullcalendar/issues/5393#issuecomment-667701320
Screenshots

Maybe someone has an idea, thank you.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 15 (2 by maintainers)
I’ve got a solution for this.
I use Tailwind for my CSS needs so all of the styles being imported by FC were undesirable to me. The trick is actually to stub out the CSS import via webpack config.
in next.config.js
{ webpack: (config) { config.resolve.alias[“./main.css”] = false; return config; } }
It’s a little dirty, so your mileage may vary depending on the size/complexity of your application… This will stub out the CSS imports being made by FullCalendar and get your imports to work.
Then in theory, if you need the FC styles, you should just be able to import the stylesheets on a case-by-case basis manually in _app.jsx or however you like.
Alternatively, follow the documentation/example that lives inside of this repo for next.js.
The reason this error occurs is that Next.js does not allow modules to import global stylesheets. FullCalendar attempts to load stylesheets and it’s baked into the core. The documented way around this is to use “next-transpile-modules” which gets around this limitation.
See https://github.com/fullcalendar/fullcalendar-example-projects/tree/10fe58abfc94457c7582af3948b3764cd17e7960/next
I’m having the same issue with simply adding
import FullCalendar from "@fullcalendar/react";to my Next.js project.@spencerwmiles Thankyou so much for that solution! I have been bashing my head against the wall for almost a full day trying to get the official example working, with no luck. Your
config.resolve.alias["./main.css"] = false;solution worked first try, and is so much cleaner and simpler!I came up with a slight variation so we can be a bit more fine-grained in stubbing out only the
*.cssfiles we need to, rather than any import of./main.cssby any code in the whole app:Note also that in Webpack v4 we apparently can’t set a resolve to
falseas it needs to be a string. But it seems that setting it to an empty string does the trick!Also i’m sure the regex in the
testcould probably be a bit cleaner/neater… but it seems to do the trick.I too am working with ckeditor and facing the same problem. Maybe I’ll juste leave Next.
Released in v6.0.0
I have the latest NextJS v13. 13.0.6 actually at the time of writing.
@peterbe As I said in https://github.com/fullcalendar/fullcalendar/issues/6674#issuecomment-1338902273:
That wasn’t my experience, I just imported them as normal from within my
_app.tsxfile and it worked as expected.Either use this: https://spacebro.io/articles/fullcalendar-nextjs-10-higher Or patch package https://github.com/ds300/patch-package with patches.zip
The first technique broke my fast refresh.