question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invariant Violation: addComponentAsRefTo while building

See original GitHub issue

Invariant Violation: addComponentAsRefTo while building searchkit

v0.10.1

Case is that if I build with: searchkit/src/core/react/SearchkitProvider.tsx

export class SearchkitProvider extends React.Component<SearchkitProps,any> {
	render(){
		return (
			<div>asdasd</div>
		);
	}
}

using by

return (
        <div>
        <SearchkitProvider searchkit={searchkit}>
            <div>
              ssss
            </div>
          </SearchkitProvider>          
          </div>
      );

I get proper response, but If I change source to


export class SearchkitProvider extends React.Component<SearchkitProps,any> {
	render(){
		return (
			<div><input ref="asdasd" /></div>
		);
	}
}

i get error Uncaught Error: addComponentAsRefTo(…): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component’s render method, or you have multiple copies of React loaded

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joemcelroycommented, Feb 17, 2017

OK i got a starter project based off create-react-app and using beta-4. This doesn’t have the multiple ref issue. https://github.com/searchkit/searchkit-starter-app

1reaction
joepiocommented, Feb 23, 2017

I had a similar error.

This often means that multiple React instances were loaded.

We managed to solve this by explicitly importing one single version of react:

// In webpack.config.js

  resolve: {
    alias: {
      react: path.resolve('node_modules/react'),
    },
  },

EDIT1: adjusted path, inostia is right.

EDIT2: However, importing React like this caused errors when building in testing environment. Module not found: ../../../node_modules/react.js in /home/runner/aod_demo/app/components/Dropdown

EDIT3: I managed to fix Module not found in our testing environment by adding this environment variable: NODE_PATH : $(pwd)/node_modules/

Read more comments on GitHub >

github_iconTop Results From Across the Web

addComponentAsRefTo Invariant Violation · GitHub
myLibrary is installed into /parentProject/node_modules/myLibrary without its dev dependencies. So when I build the main project, only one copy of react gets ...
Read more >
React ref not working Invariant Violation - Stack Overflow
I am having an issue with adding a ref to a react component. Below is the error message. invariant.js:39Uncaught Invariant Violation: ...
Read more >
Fixing the Jest Error, "Invariant Violation
Jest sometimes fails with an error, "Invariant Violation: addComponentAsRefTo". This how-to discusses a solution for the error & speculates ...
Read more >
React ref not working Invariant Violation - appsloveworld
Coding example for the question React ref not working Invariant Violation: addComponentAsRefTo-Reactjs.
Read more >
Refs Must Have Owner Warning - React
addComponentAsRefTo (…): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found