I am developing an external component (let's say my-component
, which I link to the project with npm link
(as it is in process and I need the package to reflect changes).
In the my-component
folder there are node_modules/react
and node_modules/react-dom
as they are its dependencies. However they are peerDependences, so I did not suppose to bring them into the project linking this package.
However when using npm link
, it link the whole directory, including node_modules
. So, when the project builds, it includes packages 2 times: from node_modules/*
and from node_modules/my-component/node_modules/*
.
This begins to affect when the component is using ReactDOM.findDOMNode
, it causes this error:
Warning: React can't find the root component node for data-reactid value `.0.2.0`. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.
Also, it may help to understand what's happening: the problem only appears if there are both node_modules/my-component/node_modules/react
and node_modules/my-component/node_modules/react-dom
. If there is only one of them, there is no error message.
The usual package installation does not bring such error as there is no node_modules/react-dom
there.
How is it supposed to develop an external component and the project at the same time?
question from:
https://stackoverflow.com/questions/33157904/how-to-avoid-loaded-two-copies-of-react-error-when-developing-an-external-comp 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…