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 React Basics 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 🙂

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.

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Full Stack JavaScript Techdegree Graduate 28,973 Points

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.