skip to Main Content

Why I am getting this I have install date-fns and I have trying to remove and update npm and node also remove package-lock json file but not resolved

import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

Thanks

I want to Date picker

2

Answers


  1. I just ran into the same problem. I resolved the issue by using an older version of react-datepicker.

    When you run npm install react-datepicker it will install the latest version which is 6.1.0 and was published 5 days ago.

    I picked a version from one year ago: 4.10.0

    https://www.npmjs.com/package/react-datepicker?activeTab=versions

    Un-Install your current version and re-install naming a different version

    npm uninstall react-datepicker 
    npm install [email protected] 
    

    then can apply the code

        import React, { useState } from "react";
    import DatePicker from "react-datepicker";
    
    import "react-datepicker/dist/react-datepicker.css";
    
    // CSS Modules, react-datepicker-cssmodules.css
    // import 'react-datepicker/dist/react-datepicker-cssmodules.css';
    
    const Example = () => {
      const [startDate, setStartDate] = useState(new Date());
      return (
        <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
      );
    };
    

    https://www.npmjs.com/package/react-datepicker?activeTab=readme

    Login or Signup to reply.
  2. you can use the below versions of react-datepicker and date-fns to avoid issues.
    "date-fns": "^3.3.1", "react-datepicker": "^4.25.0"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search