How to avoid `loaded two copies of React` error when developing an external component?

前端 未结 9 1658
无人共我
无人共我 2020-12-28 14:05

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 packa

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 14:32

    I was getting this because I had already included react and react-dom as external scripts in my HTML markup.

    The error was caused by adding an import ReactDOM from 'react-dom' to a component module. The error went away once I removed the import, and the module worked fine since the components were already available.

提交回复
热议问题