"Global CSS cannot be imported from within node_modules." - next.js
See original GitHub issueReduced 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.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Global CSS cannot be imported from within node_modules.
Try to import a CSS from a 3rd party lib. Expected behavior. To be able to import css. System information. OS: macOS; Chrome;...
Read more >Next.js Global CSS cannot be imported from files other than ...
Hey, I created and move the main. · @IndustryDesigns, try to use node-sass instead of @zeit/next-sass , I just tested it and updated...
Read more >Next.js: Global CSS cannot be imported from files other than ...
Global CSS errors can happen because of the improper configuration of next.config.js file. If you are using next.config.js , make sure it is ......
Read more >css-global | Next.js
An attempt to import Global CSS from a file other than pages/_app.js was made. Global CSS cannot be used in files other than...
Read more >Global CSS cannot be imported from within node_modules
Global CSS cannot be imported from within node_modules. 2022.03.21 ... within node_modules. Read more: https://nextjs.org/docs/messages/css-npm Location: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.