未捕获的TypeError:无法读取未定义的react-dom.production.min.js:760的属性“ hasOwnProperty”

时间:2019-05-06 10:34:59

标签: reactjs webpack react-dom-server

尝试打开构建项目时出现此错误

通过项目的方式在开发模式下正常运行。

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

1 个答案:

答案 0 :(得分:0)

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

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

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

现在它们具有相同的版本,最后可以一起工作。