2015-11-03 76 views
0

我正嘗試使用here中的generator-react-webpack創建一個Todos示例應用程序。一切工作,直到我開始使用alt的通量模式。當我運行使用npm run項目中,我得到了以下錯誤:與alt和webpack發生反應:@datasource出現意外的令牌

TodoStore.js: Unexpected token (12:0) 
    10 | import _ from 'lodash'; 
    11 | 
    12 | @datasource(CategorySource) 

它抱怨上面的@datasource裝飾線12。下面是我的TodoStore.js代碼:

'use strict'; 

const alt = require('../alt'); 
const Actions = require('../actions'); 
import {decorate, bind, datasource} from 'alt/utils/decorators'; 
import CategorySource from '../sources/CategorySource'; 
import _ from 'lodash'; 

@datasource(CategorySource) 
@decorate(alt) 
class TodoStore { 
    constructor() { 
     this.state = { 
      user: null, 
      todos: null, 
      todosLoading: true 
     }; 
    } 

    @bind(Actions.todosLoading) 
    todosLoading() { 
     this.setState({ 
      todosLoading: true 
     }); 
    } 

    @bind(Actions.todosReceived) 
    receivedTodos(todos) { 
     _(todos) 
     .keys() 
     .each((k) => { 
      todos[k].key = k; 
     }) 
     .value(); 

     this.setState({todos, todosLoading: false}); 
    } 

    @bind(Actions.categoriesReceived) 
    receivedCategories(categories) { 
     let selectedCategory; 
     _(categories) 
     .keys() 
     .each((key, index) => { 
      categories[key].key = key; 
      if (index == 0) { 
       categories[key].selected = true; 
       selectedCategory = categories[key]; 
      } 
     }) 
     .value(); 

     this.setState({categories, selectedCategory, todosDirty: true}); 
    } 

    @bind(Actions.login) 
    login(user) { 
     this.setState({user: user}); 
    } 
} 

export default alt.createStore(TodoStore); 

我發現this post了類似的問題,但我沒有任何運氣得到它通過改變這一行的工作:test: /\.jsx?$/,在我webpack.config。 js文件。

回答

0

找出原因:因爲它無法識別ES7裝飾器語法。我創建了一個名爲.babelrc在根文件,其內容爲:

{ 
    "stage": 0 
} 

現在一切正常!希望這將有助於未來的人。