Skip to content
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

Issue when using react/addons, related to error reported by many others: Uncaught TypeError: Cannot read property '__reactAutoBindMap' of null #3593

Closed
shaimo opened this issue Apr 5, 2015 · 18 comments

Comments

@shaimo
Copy link

shaimo commented Apr 5, 2015

I managed to isolate the issue. I have the simplest component:

var React = require('react/addons');
var Test = React.createClass({
    render: function() {
        return <div>Hello world</div>
    }
})

module.exports = Test;

And then using it:

React.render(<Test />, document.getElementById(options.element_id));

This gives the infamous:

Warning: This JSX uses a plain function. Only React components are valid in React's JSX transform. 
warning.js:36 
Warning: Something is calling a React component directly. Use a factory or JSX instead. See: http://fb.me/react-legacyfactory warning.js:48 
ReactClass.js:842 
Uncaught TypeError: Cannot read property '__reactAutoBindMap' of null

But - if you replace

var React = require('react/addons');

with

var React = require('react');

everything works fine with no errors or warnings. Is this some incompatibility with 0.13.2 and its addons part? Am I missing anything?

@sophiebits
Copy link
Collaborator

I don't know why this would be related to addons, but it sounds like you're using an old JSX transformer. Can you check if that's the case?

@shaimo
Copy link
Author

shaimo commented Apr 5, 2015

Thanks for the reply. I'm using reactify 1.1 which seems to be the most recent one. What else should I check?
Also, as mentioned - everything does seem to work ok as long as I stick to react itself without the addons. Maybe also related - I'm unable to use react-router at all: remix-run/react-router#1035

@sophiebits
Copy link
Collaborator

Can you look at the built file? Does it have React.createElement('div', or React.DOM.div(? Similarly, Test(null), or React.createElement(Test, null)?

@shaimo
Copy link
Author

shaimo commented Apr 5, 2015

Sorry for the newbie question, but I'm not sure where to find the processed file. I'm using rails with browserify and reactify and I have no idea where it puts the result js files. Can you point me to the right place? Thanks

@sophiebits
Copy link
Collaborator

You can look at the script tag in the generated HTML to see what's loaded.

@ivanflorentin
Copy link

I have the same problem with react-0.13.2:

index.html

<!doctype html>
<html lang="en">
        <head>
        <script src="external/react.js"></script>
        <script src="external/JSXTransformer.js"></script>
                <meta charset="utf-8">
                <title>React Test</title>
        </head>
        <body>
        <div id="app">Here goes the app</div>
        <script  type="text/jsx" src="test.js"></script>
        </body>
</html>

test.js:

/*
var CommentBox = React.createClass({
    render: function() {
        return (
            <div className="commentBox">
                Hello, world! I am a CommentBox.
            </div>);
        }
});

React.render(<CommentBox/>,  document.getElementById('app')); 
*/

var CommentBox = React.createClass({ 
    render: function() {
        return (React.createElement('div', null, 'Hello, world! I am a CommentBox.')); 
        }
});

React.render(CommentBox(), document.getElementById('app'));  

this gives me

Uncaught TypeError: Cannot read property '__reactAutoBindMap' of undefined

if I uncomment the upper part of the js and comment out the lower part it works.

I tried taking out JSXTransformer.js, with and without add-ons, and many other configurations without luck.

@shaimo
Copy link
Author

shaimo commented Apr 28, 2015

Make sure you are indeed using the correct version of react. In my case I had 2-3 different strange issues before I found out I was using the wrong version of React because of some dependency I was not aware of. Try "npm list react" to make sure you have only one react there...

@ivanflorentin
Copy link

I'm using only this version for the test:
https://facebook.github.io/react/downloads/react-0.13.2.zip

@shaimo
Copy link
Author

shaimo commented Apr 28, 2015

Yes, I also was sure I was only using this version, but eventually found out that was not the case because of that dependency in one of the modules I was using...

@ivanflorentin
Copy link

I'm not using npm, just plain HTML, a javascript file and the unpacked files from react. It works with react 0.12.2

@sophiebits
Copy link
Collaborator

@ivanflorentin Your CommentBox() should be React.createElement(CommentBox) or <CommentBox />.

@shaimo Closing because it sounds like you found your issue.

@sophiebits
Copy link
Collaborator

@ivanflorentin You should have seen a warning in the console too pointing this out.

@ivanflorentin
Copy link

thanks @spicyj,
changing to your sugestion gives me this:

Uncaught Error: Invariant Violation: React.render(): Invalid component element. Instead of passing a component class, make sure to instantiate it by passing it to React.createElement.

@sophiebits
Copy link
Collaborator

@ivanflorentin Your code works fine for me here:

http://jsbin.com/venaqozebi/1/edit

If you can make a repro case in jsbin for me to look at, I'm happy to investigate.

@ivanflorentin
Copy link

@spicyj
yes, it works like this: React.render(<CommentBox/>, document.getElementById('app'));
but fails withReact.render(CommentBox, document.getElementById('app')); or React.render(CommentBox(), document.getElementById('app'));

@sophiebits
Copy link
Collaborator

Yes, you need to pass an element (either React.createElement(CommentBox) or <CommentBox />) to React.render.

@ivanflorentin
Copy link

@spicyj Thank you very much, it works now.
I have a large piece of code written in 0.12.2 and there
<script src="//fb.me/react-with-addons-0.12.2.js"></script>
and
React.render(CommentBox(), document.getElementById('app'));
works fine

guess I just have to adjust the code.
thanks again for the fast response.

@sophiebits
Copy link
Collaborator

Yes, this was a deprecation introduced in 0.12 and completely removed in 0.13. See http://facebook.github.io/react/blog/2014/10/14/introducing-react-elements.html for more details. You should have received console warnings for these when running under 0.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants