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

The issue is twofold:

  1. You cannot have 2 copies of react loaded.
  2. npm link creates a symlink, however the “require” doesnt respect the
    symlink and when it tries to navigate up the directory, it never
    finds the react of the parent project.

Solution:

All you have to do is link the react and react-dom in your component to that of parent project’s node_modules folder.

Go to your component project and remove the react and react-dom then do

npm link ../myproject/node_modules/react
npm link ../myproject/node_modules/react-dom

Leave a Comment