如何在React + Material UI中解决此错误

时间:2018-05-09 12:01:19

标签: reactjs material-ui higher-order-components

尝试在Mac和Ubuntu中运行应用程序时出现以下错误。但它在Windows平台上运行没有任何错误。我该如何解决这个问题。 Material UI beta版(v1.0.0-beta.46)中是否有任何特定于平台的代码。我使用了withStyles组件,它是材料ui的高阶组件。

错误:

/node_modules/material-ui/styles/withStyles.js
Module not found: Can't resolve '@babel/runtime/core-js/map'

以下是我的代码

import React from 'react';    
import PropTypes from 'prop-types';     
import withStyles from 'material-ui/styles';    
import AppBar from 'material-ui/AppBar';    
import Toolbar from 'material-ui/Toolbar';    
import Typography from 'material-ui/Typography';    
import Button from 'material-ui/Button';    
import Avatar from 'material-ui/Avatar';    
import classNames from 'classnames';    
import AppIcon from '../../assets/img/myAppIcon.png';

const styles = theme => ({                
    root: {
        flexGrow: 1,
    },
    flex: {
        flex: 1,
    },
    menuButton: {
            marginLeft: -12,
            marginRight: 20,
    },
    loginButton:{
            alignContent: "flex-end"
    },
    avatar: {
            margin: 10,
    },
    toolbar: {
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'flex-end',
        padding: '0 8px',
        ...theme.mixins.toolbar,
    },
    content: {
        flexGrow: 1,
        backgroundColor: theme.palette.background.default,
        padding: theme.spacing.unit * 3,
    },
});

// Here is my functional component which renders the AppBar with login button at the right hand side.

function Layout(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <AppBar
          position="absolute"
          className={classNames(classes.appBar)}
        >
          <Toolbar>                    
            <Avatar src={AppIcon} className={classes.avatar} />
            <Typography variant="title" color="inherit" noWrap>
              MyApp
            </Typography>
            <Typography variant="title" color="inherit" noWrap className={classes.flex} />
            <Button color="inherit">Login</Button>
          </Toolbar>          
        </AppBar>  
        <main className={classes.content}>
            <div className={classes.toolbar} />
            {props.children}
        </main>        
    </div>
  );
}

Layout.propTypes = {
  classes: PropTypes.object.isRequired,
  theme: PropTypes.object.isRequired,
};

//Here I'm getting an error on executing this
export default withStyles(styles, { withTheme: true })(Layout);

2 个答案:

答案 0 :(得分:2)

你可以使用它,它会起作用。

npm install @babel/runtime

答案 1 :(得分:1)

试用测试版

npm install  @babel/runtime@7.0.0-beta.55