-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Confusing error message when passing non string, non component class to React.createElement #3478
Comments
Yea, we can do better than that. On the plus side, looks like this error will actually log as We should be able to catch this in |
No objects, just functions that return objects with a render function. I thought we had a warning for this already though. |
Sorry for all the references above. Let me know how this PR looks. |
Display error when trying to create an element of type `boolean`. Fixes #3478
I'm still getting this error (I just installed the latest react version). Any ideas why it happens? Everything else bundles rather alright with browserify but the main client script doesn't run and flags with this error. |
@kdamball It's a long shot, but I just had the same error, and it turned out to be a component that I was including with If it helps to narrow down the component, the hierarchy was Ancestor > ChildList > Child > ChildList > Child... (recursive). The Ancestor component was unnecessarily including the Child component. But again this is pure speculation since the error message was in no way indicative of the solution I found, so the problem in your case may be completely different :) Cheers |
@bodjkin Yep, you are right, it was totally my own error. The error reporting should be better though. It seems like frontend scripts are better at this than bundling everything using browserify. |
Thanks @bodjkin, you saved me a lot of time ;) I had simply forgotten to add the |
I just had the same issue that cosmith had. The TypeError really isn't very helpful. The real error is only tangentially related to types... |
@cosmith @johntyree Did you see a warning in the console logged before the exception was thrown? There should be one.
|
@spicyj good question. It was probably there, but I don't recall now. Why would that be a warning and not an exception itself? |
For this case specifically, it's because we want to be able to inline calls to React.createElement (#3228) without changing runtime behavior which we can do only if createElement never throws. |
Can it be made to only throw when not in I'm not sure there's a better solution than just emitting a warning before everything explodes. At the end of the day the dev is just going to Google the error because it's completely opaque. Then they'll find this thread or something similar and move on with their lives. |
Not sure if this will help someone in the future, but another way to get this same error ( So this will throw the error mentioned: const React = require( 'react' );
class MyComponent extends React.Component {
//....
} This will fix it: const React = require( 'react' );
class MyComponent extends React.Component {
//....
}
module.exports = MyComponent; |
Hopefully we can make the toUpperCase error a little less cryptic. Just posted #4154. |
Improve error message when mounting non-string/function elements
very nice 👍 |
I was trying to do . After Removing the entry it has been fixed.
|
I'm struggling with this error too. Any pointers? Here is my main app: var React = require('react');
var TestComponent = require('./components/TestComponent.jsx');
React.render(<TestComponent />, document.getElementById('id')); And here is my testcomponent.jsx: var React = require('react');
var TestComponent = React.createClass({
render: function() {
return (
<h1>asdfasdf</h1>
);
}
});
module.export = TestComponent; I'm using the latest version of rect, reactify and browserify to compile |
@runrevben In your |
@ibrahim12 Thank you! You saved me much frustration :) |
@infolock Thank you, that was the source of my bug too. |
I had the same error trying to include a component inside the same component var Foo = require('./foo.jsx');
var Bar = require('./main.jsx');
var Main = React.createClass({
render: function() {
return (
<div>
<Foo/>
<Bar/>
</div>
);
}
})
module.exports = Main; Error : TypeError: type.toUpperCase is not a function |
In 0.14, you'll get something like this message:
|
hey @spicyj, kinda late on this, but would it be possible to get the name of the invalid component? Would help finding and fixing the errors |
This isn't possible without changing the transform, no. You can look at the stack trace to see where the error was. |
the error is so confused, and difficult to trace the error |
Folks, I already made the error message better in 0.14. Please stop commenting. |
👍 |
@infolock Thank you do much!
What a terrible error message! |
The following code:
produces
deep into React.
http://jsfiddle.net/92env5pj/1/
The text was updated successfully, but these errors were encountered: