ReactJS报错 React createElement error type is invalid — expected a string ...

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. Check the render method of `Add`.
    in AdvertisementAdd (created by Connect(AdvertisementAdd))
    in Connect(AdvertisementAdd) (created by Route)
    in Route (created by Full)
    in Switch (created by Full)
    in div (created by Container)
    in Container (created by Full)
    in main (created by Full)
    in div (created by Full)
    in div (created by Full)
    in Full (created by Route)
    in Route
    in Switch
    in Router (created by ConnectedRouter)
    in ConnectedRouter
    in Provider

问题背景

使用React 15.6.1 + Webpack 3.6.0,导入一个组件

import  { Select,Option, OptGroup }  from '../../component/Tree';

结果控制台报错 ,错误信息信息如下所示: 输入图片说明

发现这种错误其实很无奈,因为很隐蔽,没有指向具体的错误代码,不太容易定位到具体代码位置。 然而经过 Google 一番搜索,在 Stack Overflow 找到个说法。

解决办法

此处原因是因为 没有导出OptionOptGroup,这两个组件是在Select 组件下引出的。 要么直接 export const Optionexport const OptGroup; 要么在Select导出: const { Option, OptGroup} = Select;;

上面的解决方法只是思路。遇到同样问题时,应该查找导入的类是否有问题,从而可以迅速的找到根源,同时也希望遇到问题的小伙伴能常去Stack Overflow摸索,各种各样的奇葩问题都能在这找到,就算找不到你想要的问题,也能有一些案例能够使你领悟。

转载于:https://my.oschina.net/johnsken/blog/1797034

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值