阵营 - ES6 - 意外标记
问题描述:
我得到这个错误阵营 - 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的东西,但我不知道,反正这是我的配置
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
"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
我得到这个错误,我需要一个额外的配置还是我做错了什么?
答
你需要https://babeljs.io/docs/plugins/transform-class-properties/
npm install --save-dev babel-plugin-transform-class-properties
和内部.babelrc
:
"plugins": ["transform-class-properties"]
+2
您可能想解释原因。 –
+0
此外,还有预设,不仅包括这个建议的语言功能,还有其他预设。例如,“stage-2”预设目前包含所有语言功能,包括ECMAScript中的第2阶段(4阶段)。 –
*“当我尝试使用箭头功能我得到这个错误” *的问题是不带箭头的功能。它的作用是'test = ...;'。 –
谢谢@FelixKling,我只是标记了它。 – Gil