每当我尝试导入DayPickerInput时,如下所示:
import DayPickerInput from 'react-day-picker/DayPickerInput';我收到ts警告:“找不到模块‘react-day-picker/DayPickerInput的声明文件。”
查看模块文件夹,似乎只有DayPicker定义了类型。
当我尝试使用如下所示的require方法时:
var DayPickerInput = require('react-day-picker').DayPickerInput;我的项目构建得很好,但当组件需要显示时,我在控制台中得到了2个运行时错误:
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。
发布于 2017-10-06 03:34:59
react-day-PickerV6.2为输入组件添加了TypeScript定义。尝试升级,看看它是否能解决您的问题。
发布于 2018-02-14 22:04:53
在7.0.7版本中,我不得不将其添加到globals.d.ts中作为一种解决方法:
declare module 'react-day-picker/DayPickerInput' {
import { DayPickerInput } from 'react-day-picker/types/DayPickerInput';
export default DayPickerInput;
}我的印象是TypeScript的定义不是最新的,并且有人(你或我?)需要更新吗?:)
发布于 2021-01-11 02:00:41
解决方案:如果您也面临这个问题,请检查在您的导入中,在react-day-picker和DayPickerInput之间是否存在“类型”。
导入的可视代码:
import DayPickerInput from 'react-day-picker/types/DayPickerInput';正确的导入:
import DayPickerInput from 'react-day-picker/DayPickerInput';发生此问题的版本:
package.json (相关包)
"dependencies": {
{ ... },
"react-day-picker": "7.4.8",
},
"devDependencies": {
{ ... },
"@types/react-day-picker": "5.3.0",
"typescript": "4.1.3",
}https://stackoverflow.com/questions/44904486
复制相似问题