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

前端 未结 9 1643
无人共我
无人共我 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:45

    I am using ReactJS.net and setup webpack from the tutorial there and started using react-bootstrap aswell when i started getting this error. I found adding 'react-dom': 'ReactDOM' to the list of externals in webpack.config.js fixed the problem, the list of externals then looked like this:

      externals: {
        // Use external version of React (from CDN for client-side, or
        // bundled with ReactJS.NET for server-side)
          react: 'React',
          'react-dom': 'ReactDOM'
    

    This seems to be the first stack overflow link on google for this error, so i thought this answer might help someone here.

提交回复
热议问题