question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Global CSS cannot be imported from within node_modules." - next.js

See original GitHub issue

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

image

Maybe someone has an idea, thank you.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
spencerwmilescommented, Aug 2, 2022

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

3reactions
CyberCyclonecommented, Jan 25, 2022

I’m having the same issue with simply adding import FullCalendar from "@fullcalendar/react"; to my Next.js project.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found