reactjs - React应用程序抛出错误: Uncaught TypeError: Cannot read property 'shape' of undefined

标签 reactjs react-proptypes

相关行位于bundle.js中:

exports["default"] = _react.PropTypes.shape({
      subscribe: _react.PropTypes.func.isRequired,
      dispatch: _react.PropTypes.func.isRequired,
      getState: _react.PropTypes.func.isRequired
    });

我刚刚升级到 React 16,并遵循了这个 tutorial调整 PropTypes。我只有一个引用 prop 类型的组件,如下所示:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

export default function (ComposedComponent) {
    class Authentication extends Component {
        static contextTypes = {
            router: PropTypes.object
        }

我在这里做错了什么?

编辑:这是我的依赖项:

"devDependencies": {
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "css-loader": "^0.28.7",
    "ignore-styles": "^5.0.1",
    "jquery": "^2.2.1",
    "jsdom": "^8.1.0",
    "loaders": "^1.1.3",
    "mocha": "^2.4.5",
    "node-sass": "^4.5.3",
    "prop-types": "^15.6.0",
    "react-addons-test-utils": "^0.14.7",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.18.2",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "axios": "^0.16.2",
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-env": "^1.6.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-1": "^6.1.18",
    "lodash": "^3.10.1",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-spinkit": "^3.0.0",
    "redux": "^3.0.4",
    "redux-form": "^7.0.4",
    "redux-thunk": "^2.2.0",
    "webpack": "^3.8.1"
  }

编辑2:即使我注释掉这一行,也会出现相同的错误。但这行是整个项目中我唯一提到 Prop 类型的地方。给出了什么?

static contextTypes = {
            router: PropTypes.object
        }

最佳答案

当前版本的 react-spinkit 尚未为 React 16.0 做好准备,因为它仍然使用现在不受支持的 React.PropTypes:

Relevant code on GitHub

最后一次提交是在 5 月 22 日。恐怕您现在无法升级 React。但看起来当前的代码已经是两者的混合体,并且只有一行需要更改,因此您只需向他们提交包含该更改的拉取请求即可。

关于reactjs - React应用程序抛出错误: Uncaught TypeError: Cannot read property 'shape' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46827364/

相关文章:

reactjs - React 组件的非必需 prop 是否应该位于 defaultProps 内

reactjs - 提供给 `children` 的无效 Prop `DropdownItem` 需要一个 ReactNode

javascript - Prop 类型 : array of one of the class instance

reactjs - 如何在使用 React-transition-group 时修复 React 15.5.3 PropTypes 已弃用警告

javascript - 为什么要在 mouseenter/mouseleave 中进行浸入操作?

javascript - 使用 testPathPattern 更新 Jest 快照

javascript - 按下回车键时更新输入值的问题

css - 使用 JSX 或 Bootstrap 定位位于列表项上的 anchor 元素的最有效方法是什么

reactjs - 什么时候执行 React PropTypes 检查?

javascript - 如何安装新版本的react app 5.0.0