Next.js issue Global CSS cannot be imported from within node_modules.
See original GitHub issueWhen installing and using the library in my next.js project, I got this issue:
./node_modules/react-gauge-chart/dist/GaugeChart/style.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/react-gauge-chart/dist/GaugeChart/index.js
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Global CSS cannot be imported from within node_modules.
I can't import a css file from a node_modules 3rd party library as described here (https://nextjs.org/docs/basic-features/built-in-css-support# ...
Read more >Next.js Global CSS cannot be imported from files other than ...
Since Next.js 9.2 global CSS must be imported in Custom <App> component. // pages/_app.js import '../global-styles/main.scss' export default ...
Read more >Next.js: Global CSS cannot be imported from files other than ...
When migrating to Next.js 9+, I was running into an issue where I could not import global styles from any file other than...
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 Free
Top 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

Decided to get a temporary fix. I have forked the repo and removed the css import from the module.
Next JS users may install the module using:
yarn add git+https://github.com/BossBele/react-gauge-chart.gitornpm install git+https://github.com/BossBele/react-gauge-chart.gitIn _app.js:
import "react-gauge-chart-nextjs-support/dist/GaugeChart/style.css";Use as “react-gauge-chart-nextjs-support”:
import GaugeChart from "react-gauge-chart-nextjs-support";This is only intended to be a temporary solution for nextJS users. Hopefully the maintainers of this project will fix this issue in the future. Meanwhile, we can’t stop coding!
@joeleduardo there is a workaround using
next-cssIn next.config.js:Then use next dynamic import with no ssr to import GaugeChart: