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

react render error:ReactDOM.render(): Invalid component element #16

Open
blueforest opened this issue Nov 5, 2015 · 5 comments
Open

Comments

@blueforest
Copy link

I render React Component on server side:

1.components.js:

var React = require('react/addons');
var MonitorApp =  React.createClass({...});
module.exports = MonitorApp;

2.appFile/app.js

 var React = require('react/addons');
var ReactApp = require('../components');
var ReactDOM = require('react-dom');
var mountNode = document.getElementById("react-main-mount");

ReactDOM.render(new ReactApp({}), mountNode);

3.gruntFile.js

browserify: {
        dist: {
            files: {
                '<%= srcBase %>/assets/app.js': ['app/appFile/*.js']
            },
            options: {
                transform: ['reactify']
            }
        }
    }

4.html

<div id="react-main-mount">
    {{{reactOutput}}}
</div>
<script src="/assets/app.js"></script>

there is a error on browser console like this:

Uncaught Error: Invariant Violation: ReactDOM.render(): Invalid component element. This may be caused by unintentionally loading two independent copies of React.

@leian-ivey
Copy link

I'm getting the same error above using gulp.

@johndevor
Copy link

Ditto

@johndevor
Copy link

Ok, I kind of figured it out. In main.js, change to this line:

ReactDOM.render(<ReactApp />, mountNode);

Not sure exactly why this works, but I got the idea from here:

https://www.bountysource.com/issues/27051749-app-main-js-line-8-react-render-new-reactapp-mountnode

If anybody can explain in further detail that would be appreciated. I'm assuming it's because react >=13.3 treats that differently... or something....

@laran
Copy link

laran commented Apr 20, 2016

That solution worked for me as well.

@jasonmorita
Copy link

jasonmorita commented Dec 15, 2017

Still workin' in December 2017

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

5 participants