我按照在线视频中的教程进行操作,但是出现了这样的错误代码:
编译失败
./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
时,代码正在运行,该按钮有效,但是没有图标出现。
但是,从教程中可以看出该程序正在运行,并带有图标。
时,这是错误代码 时的结果编辑:我现在拥有的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" ] }