2017-07-18 56 views
0

我是React的新手,试图将materialui组件集成到示例项目中。而且我现在面临以下问题:语法错误:反应项目中的意外标记

Module build failed: SyntaxError: ./app/Tabs.jsx: Unexpected token 
    (9:8) 

    7 | 
    8 | export default class IconLabelTabs extends Component { 
> 9 | state = { 
    |  ^
    10 |  index: 0, 
    11 | }; 
    12 | 

我提到一些博客,发现

​​

中的WebPack但仍面临着同样的错误。

回答

2

最有可能你缺少babel-plugin-transform-class-properties插件。

我通常会添加预设stage-0,以便让我掌握所有这些好东西。

$ npm i -D babel-preset-stage-0 

而在.babelrcwebpack装载机:

"presets": [ 
    ["es2015", { "modules": false, "loose": true }], 
    "react", 
    "stage-0" 
    ], 
+0

由于它的工作。 – Harshini

2

您必须初始化Component构造函数中的状态变量。你的情况:

./app/Tabs.jsx

export default class IconLabelTabs extends Component { 

    constructor(props) { 
     super(props); 
     this.state = {index: 0}; 
    } 
} 
+0

没有必要的,如果你使用了正确的巴贝尔插件 –