TypeError:更新后无法读取未定义的属性“ any”

时间:2019-04-10 18:26:26

标签: javascript reactjs npm typeerror babel

我在应用程序中更新了几个npm软件包,除了一个错误,我已经安全解决了很多错误!

TypeError: Cannot read property 'any' of undefined
at Object.<anonymous> (/home/cpt/Desktop/prod/local/app/components/Base/react-quick-return.js:11:24)
at loader (/home/cpt/Desktop/prod/local/node_modules/babel-register/lib/node.js:144:5)

在以下代码中:

/* eslint-disable */
import React, {PropTypes} from 'react';
import detectPassiveEvents from 'detect-passive-events';
import {getScrollTop, getSupportedCSSProperty} from 'utils/dom';
import cx from 'classnames';

const EVENTS = ['scroll', 'resize', 'load', 'pageshow'];

class QuickReturn extends React.Component {
    static propTypes = {
        component: PropTypes.any.isRequired, //HERE IS
        className: PropTypes.string
    };

我将react的版本从15.3.1更改为16.8.4

但是,我还更新了以下软件包:

    "babel-core": "6.26.3",
    "react": "16.8.4",
    "react-addons-create-fragment": "15.6.2",
    "react-addons-css-transition-group": "15.6.2",
    "react-addons-pure-render-mixin": "15.6.2",
    "react-dom": "16.8.4",
    "react-maskedinput": "4.0.1",
    "react-redux": "5.1.0",
    "react-router": "3.2.0",
    "redux": "4.0.0",
    "react-addons-test-utils": "15.6.2",

据我所知,问题出在babel-register模块中,但问题不在我的package.json

请告诉我,怎么回事?我到达了Google的第5页,并决定在这里写。

2 个答案:

答案 0 :(得分:2)

PropTypes不再生活在适当的地方。现在是import PropTypes from 'prop-types'https://reactjs.org/docs/typechecking-with-proptypes.html

答案 1 :(得分:1)

消息

Cannot read property 'any' of undefined
正如您自己发现的那样,

引用此行:

component: PropTypes.any.isRequired, //HERE IS

这意味着PropTypesundefined,这又是因为PropTypes未正确导入。您尝试使用

import React, {PropTypes} from 'react';

但是一段时间以来PropTypes不再是React本身的一部分,而是一个单独的软件包,您需要自己安装和导入。有关更多详细信息,请参见prop-types on npm

基本上,您需要添加以下行(并将PropTypes从现有的react导入中删除):

import PropTypes from 'prop-types';