React-ES6-意外令牌 [英] React - ES6 - Unexpected token
本文介绍了React-ES6-意外令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误
ERROR in ./src/components/Header/index.js
Module build failed: SyntaxError: C:/Users/Gil/Documents/Projects/ecommerce/src/components/Header/index.js: Unexpected token (16:7)
14 | }
15 |
> 16 | test = () => {
| ^
17 | console.log('pass!');
18 | };
19 |
我认为ES6可以满足要求,但是我不知道,这是我的配置
i think its something with ES6, but i dont know, anyway here's my config
webpack.config.js
webpack.config.js
loaders: [
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
{ test: /\.jsx$/, loader: 'babel-loader', exclude: /node_modules/ },
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader'
},...
package.json
package.json
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react-scripts": "1.0.7"
所以我的问题是,当我尝试使用arrow function
时出现此错误,我是否需要额外的配置,或者我做错了什么?
so my problem is, when i try to use arrow function
i get this error, do i need an extra config or i'm doing something wrong?
推荐答案
您需要 https://babeljs.io/docs/plugins/transform-class-properties/
npm install --save-dev babel-plugin-transform-class-properties
和.babelrc
内部:
"plugins": ["transform-class-properties"]
这篇关于React-ES6-意外令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文