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.

Css Modules import not working

See original GitHub issue

I am having some issues trying to get the styling to import correctly. Here’s the code:

import` React, { Component, PropTypes } from 'react';
import DatePicker from 'react-datepicker';
import moment from 'moment';

import "react-datepicker/dist/react-datepicker-cssmodules.css";

export class DateInput extends Component {
  constructor(props) {
    super(props);
  }
  state = {
    startDate: moment(),
  }

  handleChange = (date) => {
    this.setState({
      startDate: date
    });
  }

  render() {
    return (
      <DatePicker
        selected={this.state.startDate}
        onChange={this.handleChange}
      />
    );
  }
}

export default DateInput;

I have tried both imports (regular and cssModule) and have tried requiring both. When they render it looks like calendarissue We are using CSS modules and reduxForm, and when I inspect the page the classes seem to be present but have no styling in them. And the numbers are selectable and the calendar works as expected outside of the styling issue. Any and all help would be appreciated

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

23reactions
Francismbcommented, Jun 13, 2017

Solved by placing this in my index.jsx file.

require("react-datepicker/dist/react-datepicker-cssmodules.css");

17reactions
sislam6commented, Jan 15, 2018

I think its not a good idea to load the css or scss file from the index. If we are using webpack. sass loader should do this. For me I just imported from scss file and it worked fine @import "~react-datepicker/dist/react-datepicker.css"; . This should do the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS modules not working for react version 16.6.0
I had this same problem and solved it by renaming my css file to: myName.module.css. and also importing like this: import styles from...
Read more >
:Global + @import not working for me · Issue #294 · css- ...
I can't seem to import any css file globally... webpack config ... in https://github.com/facebookincubator/create-react-app/issues/343.
Read more >
Using CSS Module Scripts to import stylesheets - web.dev
Learn how to use CSS module scripts to import CSS stylesheets using the same syntax as JavaScript modules.
Read more >
How to Style React Components Using CSS Modules
CSS modules provide a way to locally scope CSS class names. You don't have to worry about overriding styles when you use the...
Read more >
How to configure CSS Modules for webpack
This increase in size can lead to loads of problems, like trying to ... We need the css-loader module to interpret @import and...
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