2017-06-05 78 views
0

我得到這個錯誤陣營 - 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我得到這個錯誤,我需要一個額外的配置還是我做錯了什麼?

+0

*「當我嘗試使用箭頭功能我得到這個錯誤」 *的問題是不帶箭頭的功能。它的作用是'test = ...;'。 –

+0

謝謝@FelixKling,我只是標記了它。 – Gil

回答

2

你需要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階段)。 –