我克隆了这个reactjs / webpack2 repo:
https://github.com/ModusCreateOrg/budgeting-sample-app
哪个效果很好,但是我正在玩游戏并使用一些属性/传播链接index.js文件:
let myprops = [1,2];
let copyprops = {...myprops};
当我运行npm start时出现构建错误:
Module build failed: SyntaxError: .../index.js:Unexpected token
它是指带有扩展运算符的行,我该如何解决这个问题? 另见:repo
答案 0 :(得分:0)
如果您没有更改该回购中包含的预设,则扩展运算符将无法正常工作。
展开运算符实际上是stage2预设的一部分。您可以在https://github.com/babel/babel-loader/issues/170
找到更多相关信息因此,为了让您的代码正常运行,您需要确保已安装babel-preset-stage-2
并将其设置为.babelrc
答案 1 :(得分:0)
class App extends Component {
render() {
let myprops = [1,2];
let [...a] = myprops;
return (
<div className="viewport">
</div>
);
}
}
仅用于快速解决方案。参考here。感谢