简体   繁体   English

Node.js:期望的表达式,得到了“ <”

[英]Nodejs: expected expression, got '<'

I'm currently using deepstream with nodejs. 我目前正在将deepstream与nodejs一起使用。 Right now, I'm following the tutorial here to get use to the new library: deepstream tutorial 现在,我将按照此处的教程使用新库: deepstream教程

However, I'm getting an error once I finish the RenderDOM part of the file. 但是,一旦完成文件的RenderDOM部分,我就会收到错误消息。 Here's the current code: 这是当前代码:

<!DOCTYPE html>
<html>
 <head>
<script src="deepstream.js"></script>
</head>
<body>
<input type="text" />
<script type="text/javascript">

    const deepstream = require('deepstream.io-client-js')
    const DeepstreamMixin = require('deepstream.io-tools-react')

    const client = deepstream('localhost:6020').login({}, () => {
      //ReactDOM.render call will go in here
      ReactDOM.render(
          <SyncedInput dsRecord="some-input" />,
          document.getElementById('example')
        )

        const SyncedInput = React.createClass({
          mixins: [DeepstreamMixin],
          setValue: function(e) {
            this.setState({value: e.target.value})
          },
          render: function() {
            return (
              <input value={this.state.value} onChange={this.setValue} />
            )
          }
        })
    })
    DeepstreamMixin.setDeepstreamClient(client)
</script>
</body>
</html>

The error shows up at this line within render:function : "input value" 错误显示在render:function的这一行:“输入值”

You are missing the dependencies required for React. 您缺少了React所需的依赖项。 Right now that error is showing up because of invalid characters found in your javascript. 现在,由于您的JavaScript中发现无效字符,该错误正在显示。 Those characters are all part of React's meta language called JSX. 这些字符都是React称为JSX的元语言的一部分。

The tutorial assumes that you have set that up. 本教程假定您已进行了设置。 There are two options for you: 有两个选项供您选择:

  1. Use Webpack to preprocess your code such that all JSX are converted to proper JavaScript 使用Webpack预处理代码,以便将所有JSX都转换为正确的JavaScript

  2. Load in browser transformers. 加载浏览器变压器。 See this tutorial for more information - https://www.sitepoint.com/getting-started-react-jsx/ 有关更多信息,请参见本教程-https: //www.sitepoint.com/getting-started-react-jsx/

I recommend going with #2 since that requires less setup. 我建议使用#2,因为这需要较少的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM