[英]How to solve webpack 2 error ,module build failed:SyntaxError,,?
I cloned this reactjs/webpack2 repo: 我克隆了这个reactjs / webpack2 repo:
https://github.com/ModusCreateOrg/budgeting-sample-app https://github.com/ModusCreateOrg/budgeting-sample-app
which is working great , but I was playing around and chaned the index.js file with some properties/spread: 这工作得很好,但我正在玩,并使用一些属性/传播链接index.js文件:
let myprops = [1,2];
let copyprops = {...myprops};
When I run npm start I get a build error: 当我运行npm start时出现构建错误:
Module build failed: SyntaxError: .../index.js:Unexpected token
It is referring to the line with the spread operator, how can I fix this? 它指的是带扩展运算符的行,我该如何解决这个问题呢? see also: repo
另见: 回购
If you haven't changed the presets that are included in that repo then the spread operator won't work as you're noticing. 如果您尚未更改该回购中包含的预设,则扩展运算符将无法正常工作。
The spread operator is actually a part of the stage2 preset. 扩展运算符实际上是stage2预设的一部分。 You can find more info on that here https://github.com/babel/babel-loader/issues/170
你可以在这里找到更多信息https://github.com/babel/babel-loader/issues/170
So in order for your code to work you'll need to make sure you've both installed the babel-preset-stage-2
and set it as a preset in your .babelrc
因此,为了使您的代码能够正常工作,您需要确保已经安装了
babel-preset-stage-2
并将其设置为.babelrc
的预设
https://www.npmjs.com/package/babel-preset-stage-2 https://www.npmjs.com/package/babel-preset-stage-2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.