0
votes

I am learning react from Udemy (React - The Complete Guide (including Hooks, React Router, Redux) by Maximilian Schwarzmüller. On the course content 4.Writing our first react code, Max uses codepen.io to import the react and reactdom cdn links and babel preprocessor. I am not using codepen.io. I am importing the react and reactdom and babel preprocessor via the script tag before my element tag. However, I get an Uncaught Syntax and Uncaught Reference error. My code is per below:-

HTML Code below

    <!DOCTYPE html>
    <html>
      <head>
        <link rel="stylesheet" type="text/css" href="./main.css">
      </head>
    <body>

       <div id="p1"></div>


       <div class="person">
       <h1>Akshar</h1>
       <p>Your Age: 27</p>
       </div>

       <script src="./app.js"></script>
       <script 
       src="https://cdnjs.cloudflare.com/ajax/libs/react/16.9.0/cjs/react.development.js"> 
       </script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.9.0/cjs/react-dom- 
      server.browser.development.js"></script>
      <script type="text/babel" src="https://cdnjs.cloudflare.com/ajax/libs/babel- 
      standalone/6.26.0/babel.js"></script>
        </body>
      </html>

CSS code below:-

      .person {
      display: inline-block;
      margin: 10px;
      border: 1px solid #eee;
      box-shadow: 0 2px 2px #ccc;
      width: 200px;
      padding: 20px;
      }

app.js code below:-

    import React from 'react';
    import ReactDOM from 'react-dom';

    function Person() {
    return (
    <div class="person">
    <h1>Max</h1>
    <p>Your Age: 28</p>
    </div>
     );
    }

    ReactDOM.render(<Person/>, document.querySelector('#p1'));
1
@nNeedOfKnowledge what is error? - Andrew
Code works fine for me. - Milind Agrawal
@MilindAgrawal I removed # from querySelector and I still get the same errors. I am using atom editor. Not sure if that piece of information is even relevant in this scenario but I thought to share it anyways. - InNeedOfKnowledge
@Andrew The error I am getting is:- Uncaught SyntaxError: Unexpected identifier react.development.js:14 Uncaught ReferenceError: process is not defined at react.development.js:14 (anonymous) @ react.development.js:14 react-dom-server.browser.development.js:14 Uncaught ReferenceError: process is not defined at react-dom-server.browser.development.js:14 - InNeedOfKnowledge
Editor should not be an issue. Seems like you have some setup issue with React otherwise your code looks fine. codesandbox.io/embed/react-example-sis86 - Milind Agrawal

1 Answers

1
votes

A couple of things here:

Check this link too.