包括导出行它不会抛出错误

时间:2016-03-30 23:04:52

标签: javascript reactjs webpack babeljs redux

  • 我正面临一个奇怪的错误
  • 当服务器运行时,我包含导出行,它不会抛出错误并且能够看到应用程序...即使它显示webpack有效 export {SportsTopPortion};
  • 但是在包含此行并再次启动服务器后,我面临错误 错误:不变违规:
  • 我正在使用webpack,节点并做出反应
  • 因为我使用webpack进行构建,我认为错误将归因于webpack
  • 选中React代码以查找错误,语法没有问题。
  • 你能告诉我如何解决它..
  • 我使用export的原因是编写单元测试用例
  • 整个代码和测试代码可以在下面的要点中看到 https://gist.github.com/js08/51e486aac90403a4946629f1d8bb985d
  • 我正在调试过去四天无法找到

代码段

export { SportsTopPortion };

export default connect(state => ({
    sportsAuthentication: state.template.sportsAuthentication,
    sportsPlayers: state.template.sportsPlayers,
    sportsUpperBar: state.template.sportsUpperBar
}))(SportsTopPortion);

错误

ERROR: Command: 'node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js' failed with exit code 1: 'Current sports_enc: development
Using DEV build configuration
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
C:\sports-whole-package\node_modules\fbjs\lib\invariant.js:45
    throw error;
    ^

Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: obje
    at invariant (C:\sports-whole-package\node_modules\fbjs\lib\invariant.js:39:15)
    at instantiateReactComponent (C:\sports-whole-package\node_modules\react\lib\instantiateReactComponent.js:64:134)
    at instantiateChild (C:\sports-whole-package\node_modules\react\lib\ReactChildReconciler.js:29:28)
    at traverseAllChildrenImpl (C:\sports-whole-package\node_modules\react\lib\traverseAllChildren.js:98:5)
    at traverseAllChildrenImpl (C:\sports-whole-package\node_modules\react\lib\traverseAllChildren.js:114:23)
    at traverseAllChildren (C:\sports-whole-package\node_modules\react\lib\traverseAllChildren.js:186:10)
    at Object.ReactChildReconciler.instantiateChildren (C:\sports-whole-package\node_modules\react\lib\ReactChildReconciler.js:52:5)
    at ReactDOMComponent.ReactMultiChild.Mixin._reconcilerInstantiateChildren (C:\sports-whole-package\node_modules\react\lib\ReactMultiChild.js:197:41)
    at ReactDOMComponent.ReactMultiChild.Mixin.mountChildren (C:\sports-whole-package\node_modules\react\lib\ReactMultiChild.js:232:27)
    at ReactDOMComponent.Mixin._createContentMarkup (C:\sports-whole-package\node_modules\react\lib\ReactDOMComponent.js:591:32)
    at ReactDOMComponent.Mixin.mountComponent (C:\sports-whole-package\node_modules\react\lib\ReactDOMComponent.js:479:29)
    at Object.ReactReconciler.mountComponent (C:\sports-whole-package\node_modules\react\lib\ReactReconciler.js:37:35)
    at [object Object].ReactCompositeComponentMixin.mountComponent (C:\sports-whole-package\node_modules\react\lib\ReactCompositeComponent.js:225:34)
    at [object Object].wrapper [as mountComponent] (C:\sports-whole-package\node_modules\react\lib\ReactPerf.js:66:21)
    at Object.ReactReconciler.mountComponent (C:\sports-whole-package\node_modules\react\lib\ReactReconciler.js:37:35)
    at [object Object].ReactCompositeComponentMixin.mountComponent (C:\sports-whole-package\node_modules\react\lib\ReactCompositeComponent.js:225:34)'

1 个答案:

答案 0 :(得分:0)

它没有那样的工作,但是那里的所有ES6为什么不一直这样做,就像文档说的那样呢?

export class SportsTopPortion extends React.Component {
  constructor(props) {
    super(props);
  }...... all the rest of your code...

//note the use of React.Component not React.createClass

或者:

module.exports = React.createClass({
    render: function() { ...

对此不确定:

export SportsTopPortion

不在底部,在顶部,您创建React类

Relevant Docs