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 React Basics (2018) First Steps in React Create a React Element

React is not defined

Hi , I download the starter files and try to run at my own device. But when I code along with teacher, the React showed red at my VScode, and when I run the console the terminal keeps saying that React is not defined. I use node to create the local server. And I also copy the latest version of CDN of React. But them both not effect the result. I'm wondering what's wrong~

const title = React.createElement( 'h1', { id: 'main-title', title: 'This is a title' }, 'My First React Element'
);

3 Answers

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Yiling Lin 👋

Could you make sure your script tags are all set up correctly? Are those new CDN links working? And also check if your app.js is the last file being imported as that depends on the React and React-dom packages to be available.

To follow along with the course you don't need to update any of the CDN links so if the above doesn't fix the issue I'd suggest to use the provided script tags:

<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="./app.js"></script>

Hope this helps 🙂

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Treehouse Project Reviewer

Also, if anyone else runs into this issue, it may be as simple as this. I just spent the last 10 minutes trying to figure this out and it was simply because I did not capitalize the 'R' in React.createElement() haha. I hope this saves somebody time.

Hi Rohald,

I found the reason that 'React not define' is that I set up the server by node, and when I run the server at terminal by enter "nodemon app.js", I got the error. Is that the reason why?? Node don't recognize React?

And I try to use live server by VS code, everything looks fine.