React-color: Uncaught Invariant Violation: addComponentAsRefTo(...):

Created on 2 Mar 2016  路  10Comments  路  Source: casesandberg/react-color

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?

need more info

Most helpful comment

@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

All 10 comments

Are you setting a ref on the component?

@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.

I have this issue as well.

Thanks !

Likewise.

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

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

Thanks @actionnick it resolved the issue !

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.

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, 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

louh picture louh  路  4Comments

foreverpinetree picture foreverpinetree  路  3Comments

scottbarrow picture scottbarrow  路  6Comments

Glutnix picture Glutnix  路  4Comments

dmgauthier picture dmgauthier  路  5Comments