未捕获的ReferenceError:未定义React

React.js

宝儿猪猪西门

2020-03-16

我正在尝试使用教程使ReactJS与rails一起使用我收到此错误:


Uncaught ReferenceError: React is not defined

但是我可以在浏览器控制台中访问React对象, 我还此处所述添加了public / dist / turbo-react.min.js并且本回答中所述还在application.js中添加了一行,但是没有运气。此外,给出错误:在此处输入图片说明
//= require components
var React = require('react')
Uncaught ReferenceError: require is not defined

谁能建议我解决该问题?

[EDIT 1]
供参考的源代码:
这是我的comments.js.jsx文件:

var Comment = React.createClass({
  render: function () {
    return (
      <div className="comment">
        <h2 className="commentAuthor">
          {this.props.author}
        </h2>
          {this.props.comment}
      </div>
      );
  }
});

var ready = function () {
  React.renderComponent(
    <Comment author="Richard" comment="This is a comment "/>,
    document.getElementById('comments')
  );
};

$(document).ready(ready);

这是我的index.html.erb

<div id="comments"></div>

第1652篇《未捕获的ReferenceError:未定义React》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android