reactjstypescriptreact-datepicker

build failed using react-datepicker


here is my code, it is a typescript procjet.

import React, { useState } from "react";
import ReactDatePicker from "react-datepicker";

export const DatePicker = () => {
    const [startDate, setStartDate] = useState<Date | null>(new Date());
    return (
      <ReactDatePicker
        selected={startDate}
        onChange={(date) => setStartDate(date)}
      />
    );
};

get the error when run build

ERROR in ../../node_modules/react-popper/lib/esm/index.js 2:0-34
Module not found: Error: Can't resolve './Popper' in '/Users/xx/pr/node_modules/react-popper/lib/esm'

ERROR in ../../node_modules/react-popper/lib/esm/index.js 3:0-36
Module not found: Error: Can't resolve './Manager' in '/Users/xx/pr/node_modules/react-popper/lib/esm'

ERROR in ../../node_modules/react-popper/lib/esm/index.js 4:0-40
Module not found: Error: Can't resolve './Reference' in '/Users/xx/pr/node_modules/react-popper/lib/esm'
...

the react-popper is 2.3.0. I jump to the react-popper/lib/esm/index.js and find the error,

Could not find a declaration file for module './Popper'.
Could not find a declaration file for module './Manager'.
Could not find a declaration file for module './Reference'. 
Could not find a declaration file for module './usePopper'.

enter image description here

can anyone help on it


Solution

  • Try to clean your node_modules and run a npm run install; References for a clean install: How do I do a clean install (delete node_modules and install) with npm