var React = require('react');
module.exports=React.createClass({
render:function(){
return(
<div>
<h1> the list </h1>
</div>
)}
})
当我运行上述代码时,出现了以下错误:
app.js:4 Uncaught TypeError: React.createClass is not a function
这是由于版本差异还是拼写错误引起的?
package.json-I have included create-react-class as seen here but not in the bower.json file
{
"dependencies": {
"browser-sync": "^2.18.13",
"browserify": "^14.4.0",
"create-react-class": "^15.6.2",
"ejs": "^2.5.7",
"express": "^4.16.0",
"gulp": "^3.9.1",
"gulp-live-server": "0.0.31",
"react": "^16.0.0",
"reactify": "^1.1.1",
"vinyl-source-stream": "^1.1.0"
}
}
gulpfile.js - 我在这个文件中是否缺少某些依赖项
var gulp= require('gulp');
var LiveServer= require('gulp-live-server');
var browserSync=require('browser-sync');
var browserify = require('browserify');
var reactify= require('reactify');
var source = require('vinyl-source-stream');
gulp.task('live-server', function(){
var server= new LiveServer('server/main.js');
server.start();
})
gulp.task('bundle',function(){
return browserify({
entries:'app/main.jsx',
debug:true,
})
.transform(reactify)
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./.tmp'))
})
gulp.task('serve',['bundle','live-server'],function(){
browserSync.init(null,{
proxy: "http://localhost:7777",
port:9001
})
})
我的main.jsx文件包含以下内容:
var React = require('react');
var createReactClass = require('create-react-class');
var GroceryItemList=require('./components/GroceryItemsList.jsx');
React.render(<GroceryItemList/>,app);
groceryitems.jsx包含以下内容:
var React = require('react');
var createReactClass = require('create-react-class');
module.exports=React.createReactClass({
render:function(){
return(
<div>
<h1> Grocery Listify </h1>
</div>
)
}
})
当我添加createReactClass时,会出现错误:createReactClass不是一个函数,当我添加导入和ES6语法时,会出现“非法的导入声明”错误。谢谢。