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

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

    I believe the answer is to specify react and react-dom as peerDependencies in your external component's package.json. As best as I can follow here and here, npm link should (as of npm@3) no longer install peerDependencies (or `devDependencies either).

    Aaaand I just read your post more carefully and realized that you already are specifying them as peerDependencies. Therefore, I think the answer boils down to:

    Upgrade to npm@3:

    npm install -g npm@3.0-latest

提交回复
热议问题