【问题标题】:TypeError: Cannot read property 'isRequired' of undefined (material ui )TypeError:无法读取未定义的属性“isRequired”(材料 ui)
【发布时间】:2019-09-26 04:28:48
【问题描述】:

我尝试从 @material-ui/core@3.9.3 切换到最新版本的材料 v4.4.3,但出现此错误

我不清楚这个问题发生在代码的哪个 sn-p 以及如何解决它。也许有人对此有一些想法?此外,您可以在 package.json 文件中检查我的所有依赖项。如果不清楚,请告诉我您需要哪些信息,我会附上。

"dependencies": {
    "@babel/runtime": "7.1.5",
    "@date-io/date-fns": "0.0.2",
    "@material-ui/core": "4.4.3",
    "@material-ui/icons": "3.0.1",
    "@material-ui/pickers": "3.2.6",
    "axios": "0.19.0",
    "classnames": "2.2.6",
    "compression-webpack-plugin": "3.0.0",
    "connected-react-router": "6.4.0",
    "date-fns": "2.0.0-alpha.27",
    "enzyme": "3.10.0",
    "enzyme-adapter-react-16": "1.14.0",
    "history": "4.6.3",
    "humps": "2.0.0",
    "jss": "^10.0.0",
    "jss-camel-case": "6.1.0",
    "jss-default-unit": "8.0.2",
    "jss-expand": "5.3.0",
    "jss-extend": "6.2.0",
    "jss-global": "3.0.0",
    "jss-nested": "6.0.1",
    "jss-props-sort": "6.0.0",
    "jss-vendor-prefixer": "8.0.1",
    "lodash": "4.17.14",
    "moment": "2.23.0",
    "normalizr": "3.3.0",
    "prop-types": "15.6.2",
    "qs": "6.5.2",
    "react": "16.8.6",
    "react-dom": "16.8.6",
    "react-dropzone": "10.1.4",
    "react-hot-loader": "4.8.8",
    "react-image": "2.1.1",
    "react-intl": "2.7.2",
    "react-intl-po": "2.2.2",
    "react-intl-redux": "2.0.2",
    "react-jss": "^10.0.0",
    "react-motion": "0.5.2",
    "react-pose": "4.0.8",
    "react-redux": "7.0.3",
    "react-router": "4.3.1",
    "react-router-dom": "4.3.1",
    "react-spinners": "0.4.7",
    "react-universal-component": "4.0.0",
    "recompose": "0.30.0",
    "redux": "4.0.1",
    "redux-axios-middleware": "4.0.0",
    "redux-devtools-extension": "2.13.8",
    "redux-form": "8.2.2",
    "redux-form-validators": "^3.2.2",
    "redux-immutable-state-invariant": "2.1.0",
    "redux-logger": "3.0.6",
    "redux-thunk": "2.3.0",
    "store2": "2.7.1",
    "uglifyjs-webpack-plugin": "2.0.1"
  }

【问题讨论】:

  • 迁移参考this链接。
  • 我已经完成了本教程中的所有步骤,但我没有看到任何变化,看到同样的错误,本教程中的哪些步骤会影响我的问题?

标签: reactjs material-ui


【解决方案1】:

我也遇到了同样的问题。更新 prop-types 包对我有用。我使用的是 prop-types@15.6.0 版本,但材料 v4 将 prop-types@^15.7.2 声明为依赖项。因此,请尝试在您的应用程序中干净地安装 prop-types。这对我有用。

  npm uninstall prop-types;
  npm install --save-exact prop-types@15.7.2;

我是怎么想出来的: 如果您单击 SelectInput.js:361,它会将您带到这一行

解析为 prop-types 包。

希望对你有帮助

【讨论】:

    【解决方案2】:

    试试这个,

    import {PropTypes} from "prop-types";
    

    【讨论】:

    • 不清楚我应该在哪里做!?问题发生在我的代码之外,在某些材料 ui 组件中,我该如何解决?
    • 请解释原因。根据道具类型文档,导入应该是 import PropTypes from 'prop-types' github.com/facebook/prop-types
    猜你喜欢
    • 1970-01-01
    • 2020-11-16
    • 2016-09-12
    • 2022-10-24
    • 2019-05-21
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 2021-09-25
    相关资源
    最近更新 更多