如何解决“请求中找不到的道具类型”错误?

时间:2018-01-07 13:16:52

标签: reactjs material-ui react-proptypes

我正在尝试使用material-ui Nextfuse-box启动新的ReactJS项目。

我已经安装了所有依赖项:

"dependencies": {
    "material-ui": "^1.0.0-beta.27",
    "material-ui-icons": "^1.0.0-beta.17",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "reflect-metadata": "^0.1.8"
 }

但我一直看到错误:“根据要求找不到道具类型”。断点在这里:

var _propTypes = require('prop-types');

exports['default'] = {
  jss: (0, _propTypes.shape)({...

知道是什么导致了这个错误吗?

我的代码

我的应用页面模仿this example provided by Material UI

import * as React from "react";
import { PropTypes } from 'prop-types'; 
import { Component } from "react";
import { render } from 'react-dom';
import { Button } from 'material-ui/Button';
import './App.css';

class App extends Component {

    constructor(props) {
        super(props);

        this.state = {
            isAuthenticated: true
        };
    }

    render() {
        const { classes } = this.props;
        const { isAuthenticated } = this.state;
        return (
            <Button raised color="primary">
              Hello World
            </Button>
        );
    }
}

App.propTypes = {
  classes: PropTypes.object.isRequired
};

export default App;

此应用程序组件在我的索引文件中呈现,如下所示:

ReactDOM.render(<App />, document.getElementById('root'));

1 个答案:

答案 0 :(得分:2)

我从fusebox here

的创作者那里得到了答案

我使用了错误的import语句:

import { PropTypes } from 'prop-types'; 

使用fusebox的正确方法是:

import * as PropTypes from 'prop-types'