简体   繁体   English

React Router的React.createElement错误

[英]React.createElement error with React Router

Code: 码:

import React from 'react'
import { render } from 'react-dom'
import { Router} from 'react-router'
 render((
  <Router>
  </Router>
 ), document.getElementById('app'))

Gives error: 给出错误:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass 

Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

I am using Browserify with Babel6 - here's the babelrc: 我在Babel6中使用Browserify-这是babelrc:

{
  "presets": ["es2015", "react"],
  "env": {
    "development": {
      "plugins": [
        ["react-transform", {
          "transforms": [{
            "transform": "livereactload/babel-transform",
            "imports": ["react"]
          }]
        }]
      ]
    }
  }
}

And package.json deps: 和package.json deps:

"axios": "^0.8.1",
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0",
"babel-plugin-react-transform": "^2.0.0-beta1",
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
"babel-plugin-transform-react-jsx": "^6.3.13",
"babel-plugin-transform-runtime": "^6.3.13",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-preset-stage-2": "^6.3.13",
"babel-runtime": "^6.3.19",
"babelify": "^7.2.0",
"browserify": "^12.0.1",
"livereactload": "^2.1.0",
"react": "^0.14.5",
"react-addons-linked-state-mixin": "^0.14.5",
"react-dom": "^0.14.3",
"react-hot-loader": "^1.3.0",
"react-mixin": "^1.1.0",
"react-proxy": "^1.1.2",
"react-redux": "^4.0.6",
"react-router": "^1.0.3",
"react-simple-router": "^0.1.6",
"reactify": "^1.1.1",
"redux": "^3.0.5",
"redux-devtools": "^3.0.1",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.1",
"redux-form": "^4.0.7",
"redux-simple-router": "^1.0.2",

Browserify config: Browserify配置:

var props = {
entries: [script],
cache: {},
packageCache: {},
plugin: isProd ? [] : (watch ? [watchify, livereactload] : [livereactload]),
transform: [
  ['babelify', {
    presets: ['es2015', 'react'],
    plugins: [
      ['react-transform', {
        'transforms': [{
          'transform': 'livereactload/babel-transform',
          'imports': ['react']
        }]
      }]

    ]
  }],
  [envify, {}]
],
extensions: ['.jsx', '.js'],
debug: !isProd,
fullPaths: !isProd // for watchify
}

Suggestion? 建议? I am finding lots of issues on GH with this but no clear solution. 我在GH上发现了很多问题,但没有明确的解决方案。 This is taken right off the examples on React Router site so not sure why I cannot get it working. 这是从React Router网站上的示例中删除的,因此不确定为什么我无法使其正常运行。 The only diff is they use webpack. 唯一的区别是他们使用webpack。

Well the issue was odd - thanks to comment I was able to resolve it. 嗯,这个问题很奇怪-感谢发表评论,我得以解决。 I have a .babelrc config as well as a browserify gulp job with its own babel config. 我有一个.babelrc配置以及一个browserify有自己的通天配置一饮而尽工作。 For some reason having both created this issue. 由于某种原因,两者都造成了这个问题。 I deleted the one in gulp and now things work fine. 我一口气删除了一个,现在一切正常。 Reason: I have zero idea. 原因:我零想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM