2

Whenever I try to import DayPickerInput like below:

import DayPickerInput from 'react-day-picker/DayPickerInput';

I get the ts warning: "Could not find a declaration file for module 'react-day-picker/DayPickerInput."

Looking at the module folder, looks like only DayPicker has types defined.

When I try to use the require method instead like below:

var DayPickerInput = require('react-day-picker').DayPickerInput;

My project builds fine but I get a 2 runtime errors in the console when the component needs to be displayed:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. 

DayPickerInput is unusable for me right now.

AnimaSola
  • 7,146
  • 14
  • 43
  • 62

3 Answers3

0

react-day-picker v6.2 added the TypeScript definitions for the input component. Try to upgrade to see if it fixes your problem.

gpbl
  • 4,721
  • 5
  • 31
  • 45
  • I have v6.2.1 and this is still a problem for me. The file for DayPickerInput is in the types folder, but it's not getting picked up by typescript for some reason. – Jonathan Oct 31 '17 at 14:47
  • Here's a sandbox of the problem I'm getting: https://codesandbox.io/s/98o50qmn8y The error is wrong in the sandbox though. The error I'm getting is "Could not find a declaration file for module 'react-day-picker/DayPickerInput." just like above. I tried looking into making a PR to fix the issue, but I saw someone else already did, which you rejected it in favor of what you have now, which doesn't work. – Jonathan Oct 31 '17 at 20:56
0

In version 7.0.7 I had to add this to globals.d.ts as a workaround:

declare module 'react-day-picker/DayPickerInput' {
  import { DayPickerInput } from 'react-day-picker/types/DayPickerInput';
  export default DayPickerInput;
}

My impression is that the TypeScript definitions are not up to date, and someone (you or me?) needs to update them? :)

Thomas
  • 355
  • 1
  • 4
  • 17
0

Solution: If you are facing this issue as well, check if there is a "types" in your import, between react-day-picker and DayPickerInput.

What Visual Code Imported:

  import DayPickerInput from 'react-day-picker/types/DayPickerInput';

The correct import:

  import DayPickerInput from 'react-day-picker/DayPickerInput';

versions in which this issue occurred:

package.json (relevant packages)

  "dependencies": {
    { ... },
    "react-day-picker": "7.4.8",
  },
  "devDependencies": {
    { ... },
    "@types/react-day-picker": "5.3.0",
    "typescript": "4.1.3",
  }
Daniel Santana
  • 1,493
  • 20
  • 19