未捕获错误:不变冲突:元素类型无效:应为字符串
Uncaught Error: Invariant Violation: Element type is invalid: expected a string
- 我正在尝试调试我的react代码
- 在我的呈现方法中,我尝试放置调试器和调试器
- 在我跳过retun方法之后,它将转到warning.js
- 在我跳过warning.js之后,如果条件为instantiateReactComponent.js
- 我不知道为什么要转到不同的文件。你能告诉我为什么要转到不同的文件吗
- 不知道如何调试
- 如果你们能给我一些解释就太好了,这样以后我就可以自己纠正错误了
-
每次时,通过函数调用提供代码片段
错误不变量.js?f23e:39未捕获错误:不变冲突:元素类型无效:应为字符串(用于内置组件)或类/函数(用于复合组件),但得到:未定义。检查
sports-container
的渲染方法。render(){const{sportsType,sportsDevice,sportsWordings,id}=this.ops;let sportsEvent=true;
debugger; if (sportsEvent === true) { return (
warning.js
/***类似于不变量,但仅在不满足条件时记录警告。*这可用于记录关键环境中的开发环境中的问题*路径。删除生产环境的日志记录代码将保留*相同的逻辑并遵循相同的代码路径。*/
var warning = emptyFunction;
if (process.env.NODE_ENV !== 'production') {
warning = function (condition, format) {
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
}
};
}
instantiateReactComponent
instance.construct(node);
/***给定一个ReactNode,创建一个将实际挂载的实例。**@param{ReactNode}节点*@return{object}元素构造函数的新实例。*@protected*/
function instantiateReactComponent(node) {
var instance;
if (node === null || node === false) {
instance = new ReactEmptyComponent(instantiateReactComponent);
} else if (typeof node === 'object') {
var element = node;
!(element && (typeof element.type === 'function' || typeof element.type === 'string')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element type is invalid: expected a string (for built-in components) ' + 'or a class/function (for composite components) but got: %s.%s', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : invariant(false) : undefined;
// Special case string values
if (typeof element.type === 'string') {
instance = ReactNativeComponent.createInternalComponent(element);
} else if (isInternalComponentType(element.type)) {
// This is temporarily available for custom components that are not string
// representations. I.e. ART. Once those are updated to use the string
// representation, we can drop this code path.
instance = new element.type(element);
} else {
instance = new ReactCompositeComponentWrapper();
}
} else if (typeof node === 'string' || typeof node === 'number') {
instance = ReactNativeComponent.createInstanceForText(node);
} else {
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Encountered invalid React node of type %s', typeof node) : invariant(false) : undefined;
}
if (process.env.NODE_ENV !== 'production') {
process.env.NODE_ENV !== 'production' ? warning(typeof instance.construct === 'function' && typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.') : undefined;
}
// Sets up the instance. This can probably just move into the constructor now.
instance.construct(node);
检查文件中的导入/需要语句,以及正在导入/需要的组件的导出。当我遇到这样的错误时,通常是因为我导入错误(ES6),即
import MyComponent from './my-component'
而不是
import { MyComponent } from './my-component'
或者我导出错误(忘记导出默认值,或者在我不想导出的时候导出为默认值),或者我完全忘记导出组件。
在我的案例中,问题是启用了nextjs swcMinify
,在大多数人的情况下,问题是导入,我认为eslint导入插件将有助于识别不良导入
相关文章:
- 警告:失败的propType:类型为“array”的无效prop应为React的“object”
- ReactJS - 元素类型无效错误
- Webgl readPixels() 无效操作:格式/类型组合无效
- 未捕获错误:不变冲突:元素类型无效:应为字符串
- 未捕获的不变冲突:元素类型无效(react、webpack、循环导入)
- 类型错误: 无效的“in”操作数 obj
- 如何使用node.js修复Twilio中无效的内容类型标头
- jQuery image丢弃无效的图像类型,并显示一条无效的消息而不是警告框
- 无效的“in”操作数 obj JQUERY - 尝试从 JSON 获取数据时出现类型错误
- 反应.js - “不变冲突:元素类型无效:预期字符串”简单按钮
- 未捕获的错误:不变冲突:元素类型无效:需要字符串(对于内置组件)或类/函数,但得到:对象
- Getting Invariant违规:使用createBrowserHistory时元素类型无效react-route
- react router问题未捕获错误:不变冲突:元素类型无效:应为字符串(用于内置组件)
- React Redux错误提供给“Provider”的“object”类型的道具“children”无效
- 轨道-“;对象值“;是属性“”的无效值;对象“;具有类型“;参考文献“;
- 节点.js类型错误:无效的非字符串/缓冲区块
- 在IE11中设置xmlHttp响应类型为msxml-document会抛出无效状态错误
- 需要帮助将js函数(限制无效字符)限制为特定的输入类型
- 从输入类型number中获取无效值
- 提供给“Dialog”的“function”类型的道具“open”无效