Javascript React.js无法读取属性'__reactAutoBindMap';空的
我知道以前有人问过这个问题,但建议的解决方案对我没有帮助,因此,我的代码由于某种原因失败了 app.js:Javascript React.js无法读取属性'__reactAutoBindMap';空的,javascript,reactjs,Javascript,Reactjs,我知道以前有人问过这个问题,但建议的解决方案对我没有帮助,因此,我的代码由于某种原因失败了 app.js: (function(React, _) { var App = require('./components/App.react'); _.mixin(_.string.exports()); var render = function() { React.render( React.createElement(App), document
(function(React, _) {
var App = require('./components/App.react');
_.mixin(_.string.exports());
var render = function() {
React.render(
React.createElement(App),
document.getElementById('reactContent')
);
};
render();
}(React, _));
然后,App.react.js:
var React = require('react');
var Test = React.createClass({
render: function() {
return <div>Hello world</div>
}
})
module.exports = Test;
感觉像是最简单的事情。。。我将包括我的package.json,以防万一
{
"name": "app",
"version": "0.0.1",
"devDependencies": {
"gulp": "3.8.10",
"gulp-run": "1.6.5",
"gulp-less": "2.0.1",
"gulp-concat": "2.4.3",
"gulp-uglify": "1.0.2",
"gulp-minify-css": "0.3.11",
"gulp-jshint": "1.9.0",
"browser-sync": "1.8.2",
"browserify": "3.44.2",
"vinyl-source-stream": "1.0.0",
"vinyl-buffer": "1.0.0",
"reactify": "latest",
"underscore": "^1.7.0",
"del": "1.1.1",
"envify": "~3.0.0"
},
"paths": {
"less": "assets/less/*.less",
"js": "./app/**/*.js",
"jsx": "./app/**/*.jsx",
"app": "./app/app.js",
"html": "*.html"
},
"dest": {
"style": "style.css",
"app": "app.js",
"dist": "dist"
},
"dependencies": {
"react": "latest",
"underscore": "^1.7.0",
"flux": "^2.0.0"
}
}
从.json文件中可以看到,这里还有很多内容,我只是重新构建了代码,以创建一个非常简单的案例并隔离问题
有什么想法吗?我认为您需要
React.createFactory(require('./components/App.React'))
,如下所述:
或使用ES6类:
编辑:
我找到了原来的博文:谢谢,但在快速浏览之后,我发现如果我使用JSX,这对我没有影响,我相信我是这样的,对吧?无论如何-将“var React=require('React')”放在app.js顶部后,它工作正常。我认为它在React.Render中工作正常,因为您没有使用jsx…哦,当它工作时:-)我最终使用了
app=React.createFactory(require('path/to/app'))
{
"name": "app",
"version": "0.0.1",
"devDependencies": {
"gulp": "3.8.10",
"gulp-run": "1.6.5",
"gulp-less": "2.0.1",
"gulp-concat": "2.4.3",
"gulp-uglify": "1.0.2",
"gulp-minify-css": "0.3.11",
"gulp-jshint": "1.9.0",
"browser-sync": "1.8.2",
"browserify": "3.44.2",
"vinyl-source-stream": "1.0.0",
"vinyl-buffer": "1.0.0",
"reactify": "latest",
"underscore": "^1.7.0",
"del": "1.1.1",
"envify": "~3.0.0"
},
"paths": {
"less": "assets/less/*.less",
"js": "./app/**/*.js",
"jsx": "./app/**/*.jsx",
"app": "./app/app.js",
"html": "*.html"
},
"dest": {
"style": "style.css",
"app": "app.js",
"dist": "dist"
},
"dependencies": {
"react": "latest",
"underscore": "^1.7.0",
"flux": "^2.0.0"
}
}