[英]“Syntax error: Unexpected keyword” in random places in react-scripts
I've recently updated my Javascript project from Webpack to react-scripts. 我最近将我的Javascript项目从Webpack更新为react-scripts。
My code structure is fairly simple. 我的代码结构非常简单。 I have a
src
folder with an index.js
that just renders the DOM like this: 我有一个带有
index.js
的src
文件夹,它仅以如下方式呈现DOM:
import ReactDOM from 'react-dom';
import Index from './pages/index';
ReactDOM.render(<Index />, document.querySelector('#root'));
and my Index
which is just a single page that renders some stuff like this: 而我的
Index
只是一个页面,呈现了如下内容:
/**
* Injected styles for this component
*/
const styles = theme => ({
...
})
class Index extends Component {
...
}
export default withRoot(withStyles(styles)(Index));
in my package.json
I use react-scripts
to start the app. 在我的
package.json
我使用react-scripts
启动应用程序。 When running npm run start
the dev-webserver starts. 在运行
npm run start
将npm run start
dev-webserver。
I can change a single letter, save the file, the dev-webserver restarts, and then I get random syntax errors throughout the code. 我可以更改一个字母,保存文件,重新启动dev-webserver,然后在整个代码中出现随机语法错误。 They look like this:
他们看起来像这样:
./src/pages/index.js
Syntax error: Unexpected keyword 'return' (144:7)
142 |
143 | if(!this.state.data){
> 144 | return null;
| ^
145 | }
146 |
147 | return <Grid>
or this 或这个
./src/pages/index.js
Syntax error: Unexpected token (76:11)
74 | */
75 | render() {
> 76 | const { classes } = this.props;
| ^
77 |
78 | return (
79 | <div className={classes.root}>
or on any other part of the project. 或项目的其他任何部分。 They keep happening until I restart npm.
它们一直发生,直到我重新启动npm。
I've tried to delete code until it doesn't happen anymore. 我试图删除代码,直到不再发生。 Then I end up with a single
React.Component
that only renders a div with text. 然后,我得到了一个只用文本渲染div的
React.Component
。
I've tried to work on another project; 我尝试过另一个项目。 the same issue happens there.
同样的问题在那里发生。
The project works fine on other devices. 该项目可以在其他设备上正常运行。
Things I've tried: 我尝试过的事情:
My node version is: 我的节点版本是:
v6.9.1 v6.9.1
My npm version is: 我的npm版本是:
v6.8.0 v6.8.0
Turns out my node version is very old (2016) . 原来我的节点版本很旧(2016年) 。
I updated node to the newest version and it stopped happening. 我将节点更新为最新版本,并且它停止发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.