patternjavascriptrailsCritical
Uncaught ReferenceError: React is not defined
Viewed 0 times
defineduncaughtreferenceerrorreactnot
Problem
I am trying to make ReactJS work with rails using this tutorial. I am getting this error:
But I can access the React object in browser console
I also added public/dist/turbo-react.min.js as described here and also added
Can anyone suggest me on how to resolve this?
[EDIT 1]
Source code for reference:
This is my
And this is my
Uncaught ReferenceError: React is not definedBut I can access the React object in browser console
I also added public/dist/turbo-react.min.js as described here and also added
//= require components line in application.js as described in this answer to no luck. Additionally,var React = require('react') gives the error:Uncaught ReferenceError: require is not defined Can anyone suggest me on how to resolve this?
[EDIT 1]
Source code for reference:
This is my
comments.js.jsx file: var Comment = React.createClass({
render: function () {
return (
{this.props.author}
{this.props.comment}
);
}
});
var ready = function () {
React.renderComponent(
,
document.getElementById('comments')
);
};
$(document).ready(ready);And this is my
index.html.erb: Solution
I was able to reproduce this error when I was using webpack to build my javascript with the following chunk in my
This above configuration tells webpack to not resolve
webpack.config.json:externals: {
'react': 'React'
},This above configuration tells webpack to not resolve
require('react') by loading an npm module, but instead to expect a global variable (i.e. on the window object) called React. The solution is to either remove this piece of configuration (so React will be bundled with your javascript) or load the React framework externally before this file is executed (so that window.React exists).Code Snippets
externals: {
'react': 'React'
},Context
Stack Overflow Q#32070303, score: 109
Revisions (0)
No revisions yet.