TypeError when using React: Cannot read property 'firstChild' of undefined

后端 未结 6 1207
误落风尘
误落风尘 2020-12-29 03:22

Sometimes, when using React libraries, such as react-router, I get this error:

Uncaught TypeError: Cannot read property \'firstChild\' of undefined

6条回答
  •  渐次进展
    2020-12-29 04:06

    This error is commonly caused by two versions of React loaded alongside.

    For example, if you npm install a package that requires a different React version and puts it into dependencies instead of peerDependencies, it might install a separate React into node_modules//node_modules/react.

    Two different Reacts won't play nicely together (at least yet).

    To fix it, just delete node_modules//node_modules/react.
    If you see a library putting React in dependencies instead of peerDependencies, file an issue.

提交回复
热议问题