Solution 1 :

As per, you need to add these two lines to your HTML file before importing your script:

<script src="[email protected]/umd/react.development.js" crossorigin></script> 
<script src="[email protected]/umd/react-dom.development.js" crossorigin></script>

I’m not sure that module loading is going to work the way you intend without using something like Create React App. You can remove the import statements and you can still reference React and ReactDOM in your script.


'use strict';

const e = React.createElement;

class LikeButton extends React.Component {
  constructor(props) {
    this.state = { liked: false };

  render() {
    if (this.state.liked) {
      return 'You liked comment number ' + this.props.commentID;

    return e(
      { onClick: () => this.setState({ liked: true }) },

// Find all DOM containers, and render Like buttons into them.
  .forEach(domContainer => {
    // Read the comment ID from a data-* attribute.
    const commentID = parseInt(domContainer.dataset.commentid, 10);
      e(LikeButton, { commentID: commentID }),

Solution 2 :

I Understand you want to create a simple application with React. I would recommend you to read this first and then this one:

A react application can be created by importing script as you have started, but it is not the recommended way to build a react app.

Once you go through the above post, find a good tutorial of your choice on platforms of your choice be it blog or video based. I can name a few like udemy, frontend masters, pluralsight, and there are many more.

Solution 3 :

Take a look at ReactJS website.

You should create React app using Node package manager
npx create-react-app appName

or should link react scripts to your html

<script src="[email protected]/umd/react.development.js"></script> 
<script src="[email protected]/umd/react-dom.development.js"></script>

Also you can’t redefine document object. This references your web page and you can access to element or DOM (Document Object Model) using document object.

Problem :

I am new to web development, This is just a simple code i created to test a new text editor I installed, I got this error while trying to import react because I was getting some other errors like; TypeError: Cannot read property ‘createElement’ of undefined

Please, how can i resolve this? is the import statement wrong?

import React, { Fragment } from 'react';
var document;//made this declaration because I got a document undefined error
const p = document.createElement("p")

p.innerHTML = "This is to test the javascript";
const body = document.querySelector("body");

<!DOCTYPE html>
  <title>Testing vs code</title>
  <link rel="stylesheet" type="text/css" href="styles.css"/>

  <h1>Testing the vscode html preview package</h1>
  <script type="module" src="js-prac.js"></script>


Comment posted by samair ali

code is not understandable , you are using react js or you want to use simple javascript ?

Comment posted by Alisha Lawani

i want to use a simple javascript

Comment posted by Dave Newton

Then why are you trying to import React?