我正在尝试使用here中的generator-react-webpack创建一个Todos示例应用。一切正常,直到我开始使用alt作为助焊剂图案。当我使用npm run
运行项目时,出现以下错误:
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遇到了类似的问题,但在我的webpack.config.js文件中更改此行:test: /\.jsx?$/
,我没有运气好转。
答案 0 :(得分:0)
找出原因:因为它无法识别ES7装饰器的语法。我在根目录下创建了一个名为.babelrc
的文件,其内容为:
{
"stage": 0
}
现在一切正常!希望这将有助于将来的某个人。