【问题标题】:Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined react-dom.production.min.js:760未捕获的类型错误:无法读取未定义 react-dom.production.min.js:760 的属性“hasOwnProperty”
【发布时间】:2019-06-27 00:22:43
【问题描述】:

我在尝试打开构建项目时遇到此错误

顺便说一下,项目在开发模式下运行良好。

Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined
    at Object.<anonymous> (react-dom.production.min.js:760)
    at m (bundle.js:1)
    at Object.<anonymous> (index.js:34)
    at m (bundle.js:1)
    at Module.56 (main.2b9897ed.chunk.js:1)
    at m (bundle.js:1)
    at Object.36 (main.2b9897ed.chunk.js:1)
    at m (bundle.js:1)
    at l (bundle.js:1)
    at Array.n (bundle.js:1)

生成错误的第 760 行。 注意变量aa是require("react");

var Tb = aa.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
Tb.hasOwnProperty("ReactCurrentDispatcher") || (Tb.ReactCurrentDispatcher = {
  current: null
});

这是我的 package.json,你注意到我使用的是最新版本的 React 和 React-Dom

{
  "name": "xxxx",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-confirm-alert": "^2.4.1",
    "react-dom": "^16.8.6",
    "react-redux": "^7.0.2",
    "react-router-dom": "^5.0.0",
    "react-scripts": "2.1.8",
    "redux": "^4.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "proxy": "http://localhost:3001",
  "devDependencies": {
    "datatables.net": "^1.10.19",
    "jquery": "^3.4.0"
  }
}

构建生成的index.html

https://pastebin.com/zUWitJH2

【问题讨论】:

  • 你能发布你的 index.html 吗?编辑:在 prod 模式下生成的那个
  • @BernardPagoaga 你可以通过pastebin.com/zUWitJH2查看它
  • 我也有同样的问题。有什么消息吗?

标签: reactjs webpack react-dom-server


【解决方案1】:

我遇到了这个问题,花了两个小时浏览网页。

然后我做了一个npm list | grep react 并意识到reactreact-dom 有不同的版本。 package.json 仅指定版本范围,但不保证它们运行在同一版本。

所以我所做的是npm rm react react-dom &amp;&amp; npm i -s react react-dom

现在他们有了相同的版本,终于可以一起工作了。

【讨论】:

  • 不错。就是这样工作的。
猜你喜欢
  • 1970-01-01
  • 2019-06-30
  • 1970-01-01
  • 2018-04-21
  • 2015-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多