简体   繁体   English

如何解决webpack 2错误,模块构建失败:SyntaxError ,,?

[英]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

well , i would do ` 好吧,我会做

class App extends Component {
render() {
    let myprops = [1,2];
    let [...a] = myprops;

    return (
        <div className="viewport">

        </div>
    );
}

} }

just for quick solution.`Reference here . 只是为了快速解决。请参阅此处 thanks 谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用React和Webpack时如何解决“模块构建失败:SyntaxError:意外令牌”错误? - How to fix “Module build failed: SyntaxError: Unexpected token” error when using React and Webpack? ./index.js中的错误模块构建失败:SyntaxError:意外的令牌 - ERROR in ./index.js Module build failed: SyntaxError: Unexpected token 模块构建失败:SyntaxError:使用webpack2时缺少类属性转换 - Module build failed: SyntaxError: Missing class properties transform when using webpack2 Webpack SyntaxError - 模块构建失败(来自./node_modules/babel-loader/lib/index.js) - Webpack SyntaxError - Module build failed (from ./node_modules/babel-loader/lib/index.js) Webpack:ES6语法使模块构建失败:SyntaxError:意外令牌 - Webpack: ES6 syntax gives Module build failed: SyntaxError: Unexpected token Webpack没有编译 - 模块构建失败 - Webpack not compiling - Module build failed Webpack / Babel 错误:模块构建失败:(SystemJS)ENOENT:没有这样的文件或目录 - Webpack / Babel Error: Module build failed: (SystemJS) ENOENT: no such file or directory 得到错误 Module not found: Error: Can&#39;t resolve &#39;../components/***&#39; when webpack build, 我该如何解决这个问题? - got error Module not found: Error: Can't resolve '../components/***' when webpack build,how can I solve this problem? 意外的令牌模块构建失败:SyntaxError - Unexpected token Module build failed: SyntaxError 模块构建失败:SyntaxError:尝试呈现第二个组件时出现意外的令牌错误 - Module build failed: SyntaxError: Unexpected token error when trying to render a second component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM