【问题标题】:React app throwing error: Uncaught TypeError: Cannot read property 'shape' of undefined反应应用程序抛出错误:未捕获的类型错误:无法读取未定义的属性“形状”
【发布时间】:2017-10-19 20:07:13
【问题描述】:

相关行在 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:即使我注释掉这一行,也会出现同样的错误。但这一行是整个项目中我唯一提到道具类型的地方。什么给了?

static contextTypes = {
            router: PropTypes.object
        }

【问题讨论】:

  • 你安装prop-types包了吗?
  • @bennygenel 我做到了。
  • 您是否使用其他软件包中的任何 3rd 方组件?
  • @bennygenel 比如什么?
  • 请添加完整的组件代码。

标签: reactjs react-proptypes


【解决方案1】:

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

Relevant code on GitHub

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

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2018-11-09
    • 2019-12-07
    • 2013-07-23
    • 2021-06-14
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    相关资源
    最近更新 更多