-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making React warn the user when createElement
is called with undefined
for the type
argument
#2607
Comments
Actually |
@gabrielecirulli Yea, seems like it wouldn't be a bad idea to have a check in createElement. @johanneslumpe What was working fine before? createElement didn't really exist (it was added in 0.11.x but would likely not have been used). And react/addons has always been the full React object with addons inserted. |
Talked it through with @johanneslumpe on IRC, same cause just not via addons. An undefined component was being used. |
@johanneslumpe Yeah, I became aware of that when I figured out what the issue is, I was just thinking it would have been way more helpful if React had told me straight away that I was passing an undefined component to |
+1, I also had this issue (albeit for a different reason) |
Thanks! 👍 |
If you are giving the whole JSX code under the script tag of the HTML page, then the order of declaration of the components could cause this issue. When the inbuilt compiler sees a component which you've later declared in the code, it'll throw an error. However in plain terms, this just means that the component is missing. |
Getting this Any solutions |
@ratneshnavlakhe Please ask on StackOverflow; this is hard to answer without seeing your complete code. |
@gaearon here is my code ...
|
import { React, Component } from 'react'; is incorrect, should be import React, { Component } from 'react'; There is no named export named |
Woah, thank you @gaearon for a nice clarification. |
I spent the last hour trying to fix an issue that was caused by me trying to render a
CSSTransitionGroup
when the actual variable was undefined.The root cause was me misinterpreting that
require("react/addons")
would return the wholeReact
instead of justReact.addons
(which is my bad), but the error itself and the stack trace were extremely cryptic and it took me a while to even get a clue that the reason why it wasn't working was that I was just trying to render an undefined type.This is the actual exception:
And here's the stack trace:
You can see that, ultimately, execution comes crashing down when React tries to look at
defaultProps
on my undefined type, which of course raises an exception.The reason why this was confusing to me is that the exception happened quite far away from the source cause and, as a secondary factor, this code worked completely fine before I started porting it to Browserify and made my mistake with
react/addons
. This lead me to a wild set of hypotheses as to why it wasn't working, such as assuming it might be due to a regression in React 0.12 (since it's been migrating fromReact.renderComponent
toReact.render
and I thoughtCSSTransitionGroup
might have been lagging behind), to thinking it could be a problem withCSSTransitionGroup
itself.The reason why I raise this issue is that, since passing an
undefined
type won't work anyway, it would make sense if React could check forundefined
and warn about it or maybe even raise an exception (since it would crash soon after anyway).My instance was a bit more extreme and if something like this happens to someone else they'll probably know where they screwed up in the first place, but some help from React would always be welcome!
The text was updated successfully, but these errors were encountered: