react-color icon indicating copy to clipboard operation
react-color copied to clipboard

Uncaught Invariant Violation: addComponentAsRefTo(...):

Open widirizki opened this issue 10 years ago • 10 comments

After installation, I got this following error:

Uncaught Invariant Violation: 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 (details: https://fb.me/react-refs-must-have-owner).

What's that mean? What's wrong with my installed package before?

widirizki avatar Mar 02 '16 03:03 widirizki

Are you setting a ref on the component?

casesandberg avatar Mar 04 '16 21:03 casesandberg

@casesandberg No, I don't set a ref at all in my component. Anything wrong with my react? I use react version 0.14.7. Should I provide another info for you? Thanks.

widirizki avatar Mar 10 '16 02:03 widirizki

I have this issue as well.

Thanks !

Mokto avatar Apr 21 '16 11:04 Mokto

Likewise.

nomadtechie avatar Apr 21 '16 18:04 nomadtechie

My issue was actually unrelated..so nevermind, :-)

nomadtechie avatar Apr 21 '16 19:04 nomadtechie

In your project directory...

rm -rf node_modules && npm install

Brute force but this works. This is caused by react-color loading up a different copy of react when bundling. You can check for multiple versions of React by doing npm ls | grep react.

More Info

actionnick avatar Apr 22 '16 19:04 actionnick

Thanks @actionnick it resolved the issue !

Mokto avatar Apr 28 '16 08:04 Mokto

I get this issue, it seems that react color picker installs react in the node modules, not sure why since its set as a peer dependancy. Deleting the react folder in the color pickers node_modules folder seems to work, however, it breaks jenkins since it reinstalls the modules on every build.

MichaelTaylor3d avatar Jun 28 '16 18:06 MichaelTaylor3d

Thanks @MichaelTaylor3D

I added postinstall scripts on package.json to workaround the issue for now.

"scripts": {
  "postinstall": "rimraf node_modules/react-color/node_modules/react"
}

hyunchulkwak avatar Jun 29 '16 02:06 hyunchulkwak

@hyunchulkwak, thanks for the workaround but I still get errors of peer dependency when I install with nested npm modules that is more than two levels.

Finally I found another solution for webpack. Just add an alias path of react to path.resolve('./node_modules/react') to use common react for all npm modules required by webpack.

Hope this helps~

Reference: http://stackoverflow.com/questions/31169760/how-to-avoid-react-loading-twice-with-webpack-when-developing

mjj2000 avatar Jul 13 '16 15:07 mjj2000