ReactJS:无法解析'@ babel / runtime / helpers / builtin / interopRequireDefault'

时间:2019-01-28 03:21:04

标签: reactjs material-ui

我按照在线视频中的教程进行操作,但是出现了这样的错误代码:

  

编译失败   ./node_modules/@material-ui/icons/Menu.js Module not found: Can't resolve '@babel/runtime/helpers/builtin/interopRequireDefault' inb'C:\LocalServer\static-page\node_modules\@material-ui\icons'   该错误在构建期间发生,无法消除。

这是我编写的代码:

import React, {Component} from 'react';
import AppBar from '@material-ui/core/AppBar';
import ToolBar from '@material-ui/core/Toolbar';
import MenuIcon from '@material-ui/icons/Menu';
import IconButton from '@material-ui/core/IconButton';

class Header extends Component{
  render(){
    return(
      <div>
        <AppBar position="fixed" style={{backgroundColor:'#2f2f2f',boxShadow:'none',padding:'10px 0px'}}>
          <ToolBar>
            <div className="header_logo">
              <div className="font_righteous header_logo_venue">The Venue</div>
              <div className="header_logo_title">MUSICAL EVENTS</div>
            </div>
            <IconButton aria-label="Menu" color="inherit" onClick={()=>console.log('open')}>
              <MenuIcon/>
            </IconButton>
          </ToolBar>
        </AppBar>
      </div>
    );
  }
}

export default Header

在教程中,我应该将目录从第4行的@material-ui/core/Menu重命名为@material-ui/icons/Menu。但是,当我恢复为@material-ui/core/Menu时,代码正在运行,该按钮有效,但是没有图标出现。

但是,从教程中可以看出该程序正在运行,并带有图标。

It has a white hamburger button icon on the header 标头上有一个白色的汉堡按钮图标

enter image description here 当我尝试将core/Menu更改为icons/Menu

时,这是错误代码

This is the result when I changed to core/Menu 这是我改回core/Menu

时的结果

编辑:我现在拥有的package.json:

{   "name": "static-page",   "version": "0.1.0",   "private": true,   "dependencies": {
    "@babel/runtime": "7.0.0-beta.55",
    "@material-ui/core": "^1.4.3",
    "@material-ui/icons": "^1.1.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-reveal": "^1.2.2",
    "react-scripts": "2.1.3",
    "react-scroll": "^1.7.9",
    "react-slick": "^0.23.1"   },   "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"   },   "eslintConfig": {
    "extends": "react-app"   },   "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"   ] }

2 个答案:

答案 0 :(得分:1)

找到了一个MUI issue,其中指出了完全相同的问题。 solution将升级到@material-ui/icons@1.1.1

由于您具有@material-ui/icons@^1.1.0作为依赖项,因此删除node_modules并再次运行npm install就足够了。

答案 1 :(得分:0)

试一试:

npm 添加@babel/runtime

或者升级 babel 运行时:

"@babel/runtime": "7.0.0-beta.55"