Multiple Copies Of React from Load 问题如何解决

Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

package.json

"dependencies": {
    "antd-mobile": "^0.8.5",
    "es6-promise": "^4.0.2",
    "extract-text-webpack-plugin": "^1.0.1",
    "html-withimg-loader": "^0.1.16",
    "isomorphic-fetch": "^2.2.1",
    "react": "^15.3.2",
    "react-dom": "^15.3.2"
  }

webpack.config.js

externals: {
    'react-dom' : 'ReactDOM'
  },

index.html中引入 外部reactdom

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1">
    <title><%= htmlWebpackPlugin.options.title %></title>
 
<script src="https://npmcdn.com/react-dom@15.3.1/dist/react-dom.js"></script>
  </head>
  <body>
  </body>
</html>

如果不使用外部依赖的话 没有错误的

阅读 5k
1 个回答
新手上路,请多包涵

我也遇到同问,楼主解决了吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题