react-google-calendar icon indicating copy to clipboard operation
react-google-calendar copied to clipboard

Global CSS cannot be imported from within node_modules.

Open LuuukDotDev opened this issue 3 years ago • 3 comments

The library does not work with next.js, because styles are incorrectly imported. See: https://nextjs.org/docs/messages/css-npm image

LuuukDotDev avatar Sep 08 '21 19:09 LuuukDotDev

This can be fixed by either bundling the CSS into the JS, or if we make users import the CSS directly.

codemonkey800 avatar Dec 03 '21 01:12 codemonkey800

This can be fixed by either bundling the CSS into the JS, or if we make users import the CSS directly.

@codemonkey800 How would I do that?

Salemoche avatar Aug 31 '22 13:08 Salemoche

I'll leave this comment if anyone is struggling with the error. I've tested my method in Next.js version 11 and it works.

  1. Install "next-transpile-modules" and "@babel/preset-react"
# yarn
yarn add next-transpile-modules @babel/preset-react

# npm
npm i next-transpile-modules @babel/preset-react
  1. Create or modify your next.config.js
const withTM = require("next-transpile-modules")([
  "@ericz1803/react-google-calendar"
])

module.exports = withTM({
  // existing custom config
});
  1. Import CSS in "_app.js" or "_app.tsx" file
import'@ericz1803/react-google-calendar/index.css'

ytakayanagi avatar Sep 02 '22 14:09 ytakayanagi

@ytakayanagi Thank you so much for the fix! For me it seemed to be a step forward, since the page actually started rendering, but the formatting is very broken, and looks like this:

SCR-20230226-mmw

Any idea what could be causing this?

garv-shah avatar Feb 26 '23 05:02 garv-shah

@garv-shah Glad, you got it to work! From the looks, the style is the only thing that needs to be fixed for you. Did you add: import'@ericz1803/react-google-calendar/index.css' You can add this import directly to the component that is displaying the calendar.

ytakayanagi avatar Feb 26 '23 05:02 ytakayanagi

Yup, the import statement is there, but it doesn't seem to make a difference, in fact it looks the same if I have it there or remove it :/

garv-shah avatar Feb 26 '23 06:02 garv-shah

I am having the same issue with NextJS! Edit: This worked for me, thanks so much.

breezyfasano avatar Mar 28 '23 21:03 breezyfasano