Uncaught TypeError: Cannot read property 'createElement' of undefined in ReactJs

Dung Do Tien Jul 19 2021 264

I have a small project with ReactJs, I want to create a small calculator and I have some form as below:

index.html

<head>
    <title>My App</title>
</head>

<body>
    <div id="myapp"></div>
</body>

index.js

import { Meteor } from "meteor/meteor";
import React from "react";
import { render } from "react-dom";

import CaculateComponent from "../../ui/App";

Meteor.startup(() => {
  render(<CaculateComponent />, document.getElementById("myapp"));
});

App.js

import { React, Component } from "react";

class CaculateComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  render() {
    return <h1>My caculating app</h1>;
  }
}

export default CaculateComponent;

When running project I get an error Uncaught TypeError: Cannot read property 'createElement' of undefined.

 TypeError: Cannot read property 'createElement' of undefined

How can I resolve it?

Thanks for any suggestions.

Have 3 answer(s) found.
  • s

    susmasagar bhattarai Jul 19 2021

    In App.js you need to command below:

    import { React, Component } from "react";

    to

    import React, { Component } from 'react';

    And it's fixed for you!

  • M

    MSIIIXI Jul 19 2021

    You need to change your tsconfig.json file should contain the following:

    {
      "compilerOptions": {
        "jsx": "react",
        "lib": ["dom", "esnext"],
        "module": "esnext",
        "esModuleInterop": true
      },
      "exclude": ["node_modules"]
    }

    rebuild and run, your issue will be fixed!

  • L

    Le Ba Tuan Anh Jul 19 2021

    You can try to change

    import React from "react";

    to

    import * as React from 'react';
    
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close