React: TypeError: Cannot read property 'createElement' of undefined

Created on 20 Sep 2017  路  6Comments  路  Source: facebook/react

TypeError: Cannot read property 'createElement' of undefined

Most helpful comment

If you want to report a bug, please fill out the questions in the issue template that you deleted before posting this. A single line from an error message is not enough information to help you.

With that said, it sounds like you're not importing React

// you have to do this if you use JSX
import React from 'react'

We try to use this issue tracker for bug reports and feature requests. If you have any additional usage or support questions, please refer to Where to Get Support for a list of helpful resources.

All 6 comments

If you want to report a bug, please fill out the questions in the issue template that you deleted before posting this. A single line from an error message is not enough information to help you.

With that said, it sounds like you're not importing React

// you have to do this if you use JSX
import React from 'react'

We try to use this issue tracker for bug reports and feature requests. If you have any additional usage or support questions, please refer to Where to Get Support for a list of helpful resources.

import * as React from 'react';

import * as React from 'react';
works fine. But sometimes I want import some more, and it's sad that I can't write like this:
import React, { Component } from 'react';

I had the same problem TypeError: Cannot read property 'createElement' of undefined
Originally I had:
import { React, Fragment } from 'react';

This solved my issue:
import React, { Fragment } from 'react';

Just in case anyone else has this simple mistake... I believe VSCode auto formatted it this way when I introduced <Fragment>

"esModuleInterop": true

adding "esModuleInterop": true to tsconfig.json + building with webpack + running the server solved the problem for me.

Was this page helpful?
0 / 5 - 0 ratings