0

Now I am trying to use DatePicker in React-hooks project. But importing css from node-module make error.

import React, { useEffect,useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import {Modal, Container, Row, Col, Button, } from 'react-bootstrap'

import { scheduleActions } from '../_actions';
import { Header } from '../_components/Header';
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css"; //this make error.

......

error image

How can I fix it? Thank you for any advice.

3
  • Please share all error messages in text form (not as screenshots!), along with your attempts to resolve the errors Commented Jul 20, 2021 at 6:15
  • Sorry for my laziness. But it's enough for fixing error. Aadesh gave me good answer then I fixed my error. Thanks for your response. Commented Jul 20, 2021 at 12:43
  • @snowman The solution (and the full problem) is also for other people that might have a similar problem. You have the opportunity to save them some time doing more research! Commented Jul 20, 2021 at 15:28

1 Answer 1

2

It could be because of the bundling logic applied in webpack configuration.

Solutions:

  1. You can use CDN, to solve the issue Add this in public/index.html file inside the head tag.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/react-datepicker/2.14.1/react-datepicker.min.css" />

Incase that doesn't help, you can check this link: https://github.com/Hacker0x01/react-datepicker/issues/879

  1. You can import it in src/index.js file instead of the current file
Sign up to request clarification or add additional context in comments.

1 Comment

You are my hero.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.