react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Css Modules import not working

Open holzru opened this issue 9 years ago • 9 comments

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

holzru avatar Jun 10 '17 00:06 holzru

@vamshikrishna144 & @narchunde solved mine by including react-datepicker/dist/react-datepicker-cssmodules.css in the webpack.config.js

holzru avatar Jun 13 '17 18:06 holzru

Solved by placing this in my index.jsx file.

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

Francismb avatar Jun 13 '17 20:06 Francismb

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.

sislam6 avatar Jan 15 '18 21:01 sislam6

frazboyz - you saved my ass 👍

yoavgecht avatar Apr 09 '18 16:04 yoavgecht

@frazboyz thanks for this.

grantglidewell avatar Jul 30 '18 21:07 grantglidewell

[1] [require-hacker] Trying to load "react-datepicker.css" as a "*.js" [1] [piping] can't execute file: /home/arun/gitlab/auquan_client/bin/server.js [1] [piping] error given was: /home/arun/gitlab/auquan_client/node_modules/react-datepicker/dist/react-datepicker.css:1 [1] (function (exports, require, module, __filename, __dirname) { .tether-element-attached-top .datepicker__triangle, .tether-element-attached-bottom .datepicker__triangle { [1] ^ [1] [1] SyntaxError: Unexpected token . [1] at new Script (vm.js:74:7) [1] at createScript (vm.js:246:10) [1] at Object.runInThisContext (vm.js:298:10) [1] at Module._compile (internal/modules/cjs/loader.js:670:28) [1] at Module._extensions..js (internal/modules/cjs/loader.js:713:10) [1] at require.extensions.(anonymous function) (/home/arun/gitlab/auquan_client/node_modules/babel-register/lib/node.js:152:7) [1] at Object._module2.default._extensions.(anonymous function) [as .js] (/home/arun/gitlab/auquan_client/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:260:68) [1] at Module.load (internal/modules/cjs/loader.js:612:32) [1] at tryModuleLoad (internal/modules/cjs/loader.js:551:12) [1] at Module._load (internal/modules/cjs/loader.js:543:3) [1] [piping] further repeats of this error will be suppressed...

@holzru @sislam6 @frazboyz I am still getting above error, react version: "react": "0.14.8" react-datepicker version: "react-datepicker": "^0.13.0" what I tried:

  1. importing css file as per react-datepicker docs
  2. copied css file and add it in same directory then imported css file
  3. configured web pack configuration to load css but still not worked for me. help would be appreciated. Thanks

arun-topagi avatar Mar 01 '19 11:03 arun-topagi

@AKArunkumar even i am also getting same error. if you found anything related to that. kindly share here. highly useful.

SivaGanesh56 avatar Jul 15 '20 16:07 SivaGanesh56

I was having an issue with webpacker where it worked in dev, but not in other environments. I had to add

@import 'react-datepicker/dist/react-datepicker';

To application.scss rather the inline import.

ndnenkov avatar Jun 15 '21 15:06 ndnenkov

@AKArunkumar @maksimdegtyarev That error to me looks like your webpack config is misconfigured. It is trying to handle css files like js files.

Francismb avatar Jun 15 '21 20:06 Francismb