我已经开始在 Python Flask 后端使用 ReactJS。
通过 Flask 渲染模板时,我在 Chrome 控制台中收到以下客户端错误。
错误:找不到module“jstransform/visitors/es6-templates-visitors”
服务器:
@app.route("/")
def start():
return render_template('index.html')
客户端: index.html
<html lang="en">
<head>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<script src="{{ url_for('static', filename='js/jquery-1.11.2.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/react.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/JSXTransformer.js') }}"></script>
<script src="{{ url_for('static', filename='js/showdown.js') }}"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="content"></div>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{{ url_for('static', filename='js/ie10-viewport-bug-workaround.js') }}"></script>
<script type="text/jsx" src="{{ url_for('static', filename='js/golden-record.js') }}"></script>
</body>
</html>
为什么这会导致问题,每个文件似乎都在静态中找到。为什么 JSX 会失败?我是否必须先将 JSX 编译成 Javascript?
谢谢
更新:
Golden-record.js
var SearchBox = React.createClass({...});
React.render(
<SearchBox url="http://localhost:5000"/>,
document.getElementById('content')
);