react:Uncaught Error:Parse Error:第5行:意外的令牌ILLEGAL

时间:2015-05-06 16:43:06

标签: nginx reactjs

我无法理解为什么以及这个错误是什么 - 你知道为什么吗?

更新:我在nginx docker容器中运行它。

错误讯息:

Uncaught Error: Parse Error: Line 10: Unexpected token ILLEGAL

 at http://x.x.x.x/scripts/example.js:10:undefined

enter code here... R OTHER DEALINGS IN THE SOFTW

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Hello React</title>
    <!-- Not present in the tutorial. Just for basic styling. -->
    <link rel="stylesheet" href="css/base.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/JSXTransformer.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
  </head>
  <body>
    <div id="content"></div>
    <script type="text/jsx;harmony=true" src="scripts/example.js"></script>
  </body>
</html>

脚本/ example.js

var Simple = React.createClass({

  getInitialState: function(){
    return { count: 0 };
  },

  handleMouseDown: function(){
    alert('I was told: ' + this.props.message);
    this.setState({ count: this.state.count + 1});
  },

  render: function(){

    return <div>
      <div className="clicker" onMouseDown={this.handleMouseDown}>
        Give me the message!
      </div>
      <div className="message">Message conveyed
        <span className="count">{this.state.count}</span> time(s)</div>
    </div>
    ;
  }
});

React.render(<Simple message="Keep it Simple"/>,
                  document.body);

2 个答案:

答案 0 :(得分:0)

我在NGINX中运行没有问题,我怀疑这是一个问题,但你永远不知道它是否是某种JSX编译器问题。您可以尝试以下操作,看看它在您的环境中是否具有相同的结果?

var Simple = React.createClass({

  getInitialState: function(){
    return { count: 0 };
  },

  handleMouseDown: function(){
    alert('I was told: ' + this.props.message);
    this.setState({ count: this.state.count + 1});
  },

  render: function(){
    render (
      <div>
      <div className="clicker" onMouseDown={this.handleMouseDown}>
        Give me the message!
      </div>
      <div className="message">Message conveyed
        <span className="count">{this.state.count}</span> time(s)</div>
    </div>
     )
  }
});

React.render(<Simple message="Keep it Simple"/>,
                  document.body);

答案 1 :(得分:0)

问题:
nginx正在缓存中 解决方案:
将nginx.conf设置为&#34; expires off;&#34;