【发布时间】:2017-04-26 02:04:52
【问题描述】:
在由于缺乏对 Commonjs 模块的支持而对 react_rails gem 感到沮丧之后,我正在测试来自 netguru 的 react_webpack_rails gem。但从那以后我得到了一个不变的违反。
例如,如果我正在用 ES6 语法编写一个简单的 Hello World 组件:
import React from 'react';
class tasksBox extends React.Component {
render() {
return <div>Hello World</div>;
}
}
export default tasksBox;
提出这些错误:
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
非常感谢您的帮助,我不知道错误来自哪里。
【问题讨论】:
-
那里的代码没有问题,所以问题出在其他地方
-
您究竟想如何渲染
tasksBox? -
如果更改大小写确实可以解决问题,那么您的实际代码肯定有所不同。
-
不,我创建了一个只有这个组件的新应用程序。我正在使用的设置可以在那里找到github.com/netguru/react_webpack_rails