Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gcaggia opened this issue Jun 5, 2020 · 16 comments
Open

Comments

@gcaggia
Copy link

gcaggia commented Jun 5, 2020

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
@BossBele
Copy link
Contributor

Got the same issue

@sunshine9249
Copy link

I've got the same issue. I tried npm install @types/react-gauge-chart and it worked!

@BossBele
Copy link
Contributor

I've got the same issue. I tried npm install @types/react-gauge-chart and it worked!

Did not work for me

@shamoons
Copy link

Same - not working for me

@BossBele
Copy link
Contributor

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!

@younes6970
Copy link

@BossBele thanks

@BossBele
Copy link
Contributor

BossBele commented Sep 6, 2020

@BossBele thanks

@younes6970 You're welcome!

@joeleduardo
Copy link

joeleduardo commented Nov 12, 2020

Hi i tried your solution but is not working @@BossBele.... looks like deleting this line the problem is solved

https://github.com/BossBele/react-gauge-chart/blob/master/dist/GaugeChart/index.js#L14

@BossBele
Copy link
Contributor

@joeleduardo It was commented earlier.. Looks like the recent push was not efficient. It is fixed now

@joeleduardo
Copy link

Do you know when will be merged your changes? (to the main repo) @BossBele

@BossBele
Copy link
Contributor

Not exactly Sir @joeleduardo but It is in the process. However, there is another workaround (using next-css) I am currently verifying. If it works, there won't be a need for the Pull Request to be merged. I will post here my findings.

@BossBele
Copy link
Contributor

BossBele commented 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>
    )
}

@Martin36
Copy link
Owner

@BossBele Your pull request is merged with master now

@joeleduardo
Copy link

@BossBele i believe that @zeit/next-css will be deprecated

@BossBele
Copy link
Contributor

@joeleduardo Oh, okay

@jaywcjlove
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants