You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React-select渲染触发错误#130致React应用崩溃,求解决方案

解决react-select集成时的元素类型无效错误

核心问题原因

错误#130的本质是你导入react-select的方式不正确,导致ReactSelect变量指向的是一个模块对象而非组件本身。

解决方案

1. 修正导入语句

如果使用CommonJS的require语法,必须获取模块的默认导出:

const ReactSelect = require('react-select').default;

或者改用ES6导入语法(推荐):

import ReactSelect from 'react-select';

2. 确认options格式正确性

确保listOptionConstructor返回的数组中,每个对象都严格包含value和label两个属性,且属性名无拼写错误,示例格式:

[
  { value: 'option1', label: '选项1' },
  { value: 'option2', label: '选项2' }
]

3. 验证版本兼容性

确认你的React版本与react-select版本匹配:

  • react-select v4/v5 需要React 16.8.0及以上版本
  • 若使用React 16.7及以下,需降级到react-select v3

内容的提问来源于stack exchange,提问作者August Guenther

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 04:27:29