Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Garrett Hughes
seal-mask
.a{fill-rule:evenodd;}techdegree
Garrett Hughes
Python Development Techdegree Student 32,971 Points

Getting http-server to look in the correct folders

I'm just trying to build a react hello world app but can't seem to get it to work.

I cd to the correct directory then run 'http-server -p 3000' but it won't render the react element correctly. In dev tools it says "unexpected token '<' on line 2'. There's not a '<' anywhere in my app.js file so I'm guessing it's not looking in the correct directory.

I installed http-server globally, but like I said, I navigated to the directory that the files I'm working on are in.

This is all I've got in the directory;

React-ChessClock (directory)
---app.js
---index.html
---styles.css
<!--index.html file-->
 <!DOCTYPE html>
 <html lang="en">

  <head>
     <meta charset="UTF-8">
     <title>TITLE</title>
     <meta name="description" content="DESCRIPTION">
     <!-- <link rel="stylesheet" href="PATH"> -->
  </head>

  <body>
    <div id="root">Loading...</div>
  <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
  <script src="app.js"></script>
  </body>
 </html>
//app.js file
const header = React.createElement(
  'h1',
  null,
  "Hello React!"
);

ReactDOM.render(
  header,
  document.getElementById('root')
);

Anyone got any advice? lol

3 Answers

Garrett Hughes
seal-mask
.a{fill-rule:evenodd;}techdegree
Garrett Hughes
Python Development Techdegree Student 32,971 Points

Dangit. Tried to change it to a component and now it's back to the 'unexpected token <' error.

function Header() {
  return (
    <div>
      <h1>5:00</h1>
    </div>
  );
}

ReactDOM.render(
  <Header />,
  document.getElementById('root')
);

Is my syntax incorrect somewhere?