Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?