428701 (1) [Avatar] Offline
#1
When trying to get the very first hello world example running the following errors occur

Uncaught SyntaxError: Unexpected token < react.js:7
Uncaught SyntaxError: Unexpected token < react-dom.js:7
Uncaught ReferenceError: React is not defined (index):9

Using http-static

Likely a simple way to fix but the solution is not obvious to a novice.

<html>
  <head>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
  </head>
  <body>
    <div id="content"></div>
    <script type="text/javascript">
      var h1 = React.createElement('h1', null, 'Hello world!')
      ReactDOM.render(
        h1,
        document.getElementById('content')
      )
    </script>
  </body>
</html>


easante (97) [Avatar] Offline
#2
Can you show the structure of your project directory and the contents of your js folder?
Azat Mardan (41) [Avatar] Offline
#3
428701 wrote:When trying to get the very first hello world example running the following errors occur

Uncaught SyntaxError: Unexpected token < react.js:7
Uncaught SyntaxError: Unexpected token < react-dom.js:7
Uncaught ReferenceError: React is not defined (index):9

Using http-static

Likely a simple way to fix but the solution is not obvious to a novice.

<html>
  <head>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
  </head>
  <body>
    <div id="content"></div>
    <script type="text/javascript">
      var h1 = React.createElement('h1', null, 'Hello world!')
      ReactDOM.render(
        h1,
        document.getElementById('content')
      )
    </script>
  </body>
</html>




It can't understand your syntax. Make sure this is HTML and also make sure you have the react.js file from where you are including it with <script>.

Refer to GitHub for the tested and working code.
echeadle (85) [Avatar] Online
#4
Did you cut and paste this code from the book? I have found that cutting and pasting from PDF's to leave hidden characters in funny places. You can try cutting and pasting to a really dumb text editor and then into the file. Something like vi or notepad are good choices, or usually I find the problem is where they break a long line into a shorter line; due to a books line length limitation. If you backspace the line until you get one long line often time you will backspace over the offending character.

Also there are editors that show the hidden characters, but I don't spend the time. Also I usually type the code in, because it slows down my brain to let the information sink in. But that is just me. You have to find your own way. I do cut and paste trivial examples, and this is where I found out about the problem with hidden characters.
echeadle (85) [Avatar] Online
#5
I cut and pasted the code you put into this forum message and it worked. So I think the issue is a hidden character in your code because you might have cut and pasted it from the PDF.
echeadle (85) [Avatar] Online
#6
Also the first post might be correct. After reading the error messages, I think the first poster may have a point. I am very new to react (I am on chapter 2 of the first book I have read on the topic) But, since it cannot find React, are you sure you have the js folder in the same folder as the index file with the two react files in it? The earlier messages are what I focused on and have seen when there are hidden characters, so I did not see the message about React undefined.