代码:
import React from 'react'
import { render } from 'react-dom'
import { Router} from 'react-router'
render((
<Router>
</Router>
), document.getElementById('app'))
给出错误:
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.
我正在使用Browserify和Babel6 - 这里是babelrc:
{
"presets": ["es2015", "react"],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "livereactload/babel-transform",
"imports": ["react"]
}]
}]
]
}
}
}
和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:
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
}
建议?我发现很多关于GH的问题,但没有明确的解决方案。这是在React Router站点上的示例中进行的,因此不确定为什么我无法使其工作。唯一的区别是他们使用webpack。
答案 0 :(得分:0)
这个问题很奇怪 - 多亏了评论我能够解决它。我有一个.babelrc
配置以及一个带有自己的babel配置的browserify
gulp作业。出于某种原因,两者都创造了这个问题。我在gulp中删除了那个,现在一切正常。理由:我没有想法。