当我点击npm start时,我有以下错误:
Parsing error: 'import' and 'export' may only appear at the top level当我调查这个错误时,他们说我需要更新eslint配置文件,并在解析器选项中放入true等等。但是,我没有eslint配置文件,我的包json看起来像这样:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^3.6.1",
"@material-ui/icons": "^3.0.1",
"material-icons-react": "^1.0.4",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-scripts": "2.1.1",
"truffle-contract": "^4.0.0-beta.1",
"web3": "^1.0.0-beta.36"
},
"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"
]
}更新:整个错误:
./src/App.js
Line 131: Parsing error: 'import' and 'export' may only appear at the top level
129 | );
130 |
> 131 | export default App;
| ^
132 |
133 | <div id="dashboard">
134 | <div className="menu">链接到我的App.js代码:
更新错误2:
./src/Article.js
Line 11: Parsing error: Unexpected token, expected ","
9 | return (
10 | {/* sorting articles by score */}
> 11 | articles.sort(function (a, b) {
| ^
12 | return a.score - b.score;
13 | });
14 |发布于 2019-06-14 10:52:56
import和export语句不能位于函数或类定义内,它们必须位于模块级别。
import something from './file'; // <-- module level, outside function
function App() {
export default App; // <-- inside function, this will break everything
return <div>Hello</div>
}
export default App // <-- module level, outside function错误非常明显:在render方法中间有一条额外的export语句。
看起来你有一些重复的代码render。删除以下行:https://github.com/AdenSTL/stackoverflow-errors/blob/master/App.js#L131-L153
所以render看起来像这样:
render() {
return (
<AppBar position="static">
<div id="dashboard">
<div className="menu">
<MenuItem onClick={this.handleClose}>
<NavLink exact to="/CardStack">
Home
</NavLink>
</MenuItem>
<MenuItem onClick={this.handleClose}>
<NavLink exact to="/Article" >
Article
</NavLink>
</MenuItem>
</div>
<div className="content">
<Route exact path="/CardStack" component={CardStack} />
<Route exact path="/Article" component={Article} />
</div>
</div>
</AppBar>
);
}https://stackoverflow.com/questions/56590452
复制相似问题