react: Make createElement(undefined) warning more descriptive

Update: claimed by @jin

This is what I see when I mistype an import:

screen shot 2016-07-19 at 21 12 01

This is not very useful.

When type is undefined, we should provide a better message. In 95% of cases it is caused by an invalid import. We should create a page explaining common cases how this could happen (e.g. mismatching default/named export, forgetting to export the component, or importing a non-existing named export), and link to that page from the warning.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 11
  • Comments: 24 (5 by maintainers)

Most upvoted comments

Can I look into this?

Please include a stacktrace! This is the worst possible message to get after doing a big merge as there are absolutely nothing to guide you to where the problem can be.

I think this was fixed in #8612, and being further improved in #8495. Thanks for the offer to help though!

@joelseq I totally dropped the ball on this one, sorry! Please take over if you’d like to!

On Mon, Dec 5, 2016 at 12:26 AM Joel Sequeira notifications@github.com wrote:

Is this still being worked on or can I maybe try to take a stab at it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/facebook/react/issues/7307#issuecomment-264770782, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVPDiwSsIeKR8BZdYqveR6DP9EOGzBJks5rE6BygaJpZM4JQIG3 .

As discussed in #7485, I think we should also report /what/ value we saw, rather than just a list of forbidden types. Compare

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).

with:

Warning: React.createElement: 5 is an invalid value for type. It should be a string (for DOM elements) or a ReactClass (for composite components).

@Pajn Will do! I’m bitten by the lack of information many times too, especially when dealing with HOC.

Edit 7/26: didn’t manage to find time last week to work on this, but will be doing that this week

I’m “assigning” myself so I keep track of this issue but it’s yours.