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.

Next.js issue Global CSS cannot be imported from within node_modules.

See original GitHub issue

When 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
BossBelecommented, Jul 27, 2020

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.git or npm install git+https://github.com/BossBele/react-gauge-chart.git

In _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!

2reactions
BossBelecommented, Nov 13, 2020

@joeleduardo there is a workaround using next-css In next.config.js:

const withCSS = require("@zeit/next-css");

module.exports = withCSS();

Then use next dynamic import with no ssr to import GaugeChart:

const GaugeChart = dynamic(() => import("react-gauge-chart"), { ssr: false });

export default function MyComponent(props) {
  return (
                <div>
                  <GaugeChart
                    id="gauge-chart1"
                    arcsLength={[0.2, 0.3, 0.5]}
                    colors={["#EA4228", "#F5CD19", "#5BE12C"]}
                    percent={0.1}
                  />
                </div>
    )
}
Read more comments on GitHub >

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

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