【问题标题】:react : Uncaught Error: Parse Error: Line 5: Unexpected token ILLEGAL反应:未捕获的错误:解析错误:第 5 行:意外的令牌非法
【发布时间】:2015-05-07 18:03:33
【问题描述】:

我不明白为什么会出现这个错误以及出现什么错误 - 你知道为什么吗?

更新:我在 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);

【问题讨论】:

  • 我将您的代码放入 jsfiddle 中(只需更改 renderComponent => render 即可更新到最新的 ReactJS 表单),它似乎可以工作:jsfiddle.net/smmccrohan/vmthzsj5
  • 好的,谢谢。我在带有 nginx 的 docker 容器中运行它,然后我收到错误 - 嗯?
  • 有趣。我认为您的问题出在执行环境中。您的代码本身看起来还不错。
  • 好的,感谢收看。

标签: nginx reactjs


【解决方案1】:

我在 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);

【讨论】:

  • 谢谢,这应该可行 - 它必须是 nginx 的东西。当我运行 docker run --name webclient -v "$PWD":/usr/share/nginx/html -p 80:80 -d nginx 时,我可以在 chrome 检查器中看到旧的 index.html 文件。今天我得休息一下。谢谢。
【解决方案2】:

问题:
nginx 正在缓存
解决方案:
将 nginx.conf 设置为“expires off;”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2014-02-09
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2013-02-20
    • 2012-10-18
    相关资源
    最近更新 更多