ReactJS: “Uncaught SyntaxError: Unexpected token <”

前端 未结 9 1610
天命终不由人
天命终不由人 2020-11-27 02:45

I am trying to get started building a site in ReactJS. However, when I tried to put my JS in a separate file, I started getting this error: \"Uncaught SyntaxError: Unexpecte

相关标签:
9条回答
  • 2020-11-27 03:46

    UPDATE -- use this instead:

    <script type="text/babel" src="./lander.js"></script>
    

    Add type="text/jsx" as an attribute of the script tag used to include the JavaScript file that must be transformed by JSX Transformer, like that:

    <script type="text/jsx" src="./lander.js"></script>
    

    Then you can use MAMP or some other service to host the page on localhost so that all of the inclusions work, as discussed here.

    Thanks for all the help everyone!

    0 讨论(0)
  • 2020-11-27 03:49

    If you have something like

    Uncaught SyntaxError: embedded: Unexpected token
    

    You probably missed a comma in a place like this:

      var CommentForm = React.createClass({
      getInitialState: function() {
          return {author: '', text: ''};
    
      }, // <---- DON'T FORGET THE COMMA
    
      render: function() {
          return (
          <form className="commentForm">
              <input type="text" placeholder="Nombre" />
              <input type="text" placeholder="Qué opina" />
              <input type="submit" value="Publicar" />
          </form>
          )
      }
      });
    
    0 讨论(0)
  • 2020-11-27 03:51

    Add type="text/babel" as an attribute of the script tag, like this:

    <script type="text/babel" src="./lander.js"></script>
    
    0 讨论(0)
提交回复
热议问题