react-bootstrap: Invariant violation when adding Navbar
I’m getting this error message
Error: Invariant Violation: addComponentAsRefTo(…): Only a ReactOwner can have refs. This usually means that you’re trying to add a ref to a component that doesn’t have an owner (that is, was not created inside of another component’s
rendermethod). Try rendering this component inside of a new top-level component which will hold the ref.
when adding the following code:
<Navbar>
<Nav navbar right>
<NavItem onClick={this.props.handleCSV} href="#">Import CSV</NavItem>
</Nav>
</Navbar>
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 38 (13 by maintainers)
I had this issue as well. Even with a single package, webpack loaded mulitple versions of react. Adding this to the webpack config helped resolve the problem.
resolve: { alias: { react: path.resolve(‘./node_modules/react’), }, },
Hmm. I made 99.99% certain that there isn’t any duplicate react. Also i use webpack
aliasto double sure that there is no duplicate react. From my debugging, i have found that theownerof theNavbarorDropdownis null which causing this issue. I don’t see the same issue with other B-R components.I’m also experiencing the same problem, using browserify and babel to generate a final bundle.js It only works if I remove the navbar. This is a new project and it’s pretty clean. I only have this issue with React Bootstrap. I’m using hundreds of components with this setup and don’t have any problem.
I believe it should be fixed. In order to make RB more popular, it should work in more environment configurations.
My package.json dependencies:
Command for compiling:
browserify -t [ babelify --presets [ react ] ] lib/client.jsx -o public/bundle.jsThe code of the Navbar (copied and pasted from exemples):
I found my issue.
Since I’m using
react-domto render my page, I forgot to add the ReactDOM external to my webpack config file and I also forgot to include the ReactDOM distribution file to my html page.And in the head of my HTML file:
Hope this helps someone.
@fedevela you apparently also don’t have react-bootstrap installed?