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

后端 未结 6 1170
误落风尘
误落风尘 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:00

    It seems to me peerDependencies is not getting traction. See https://github.com/npm/npm/issues/5080#issuecomment-40545599

    I am maintaining react-date-picker (and other react modules), and what I've done until now is to specify the React dependency using the caret, for example ^0.12.0.

    Also, when doing a build will all concatenated files, for use outside of the npm ecosystem, I use webpack with externals: { 'react': 'React'} which will look for the global var React.

提交回复
热议问题