【发布时间】:2018-04-18 09:05:25
【问题描述】:
我在尝试在电子、反应、redux 项目中使用装饰器时遇到了一个严重的语法错误。
Failed to compile B:/Projekte/sketches/electron-react-get-
started/app/pages/Layout.js: B:/Projekte/sketches/electron-react-get-
started/app/pages/Layout.js: Unexpected token (7:0)
SyntaxError: B:/Projekte/sketches/electron-react-get-
started/app/pages/Layout.js: Unexpected token (7:0)
5 | import {fetchUsers} from "../actions/userActions";
6 |
> 7 | @connect((store) => {
| ^
8 | return {
9 | users: store.users
10 | }
at Parser.pp$5.raise (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:4454:13)
at Parser.pp.unexpected (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:1761:8)
at Parser.pp$1.parseDecorator (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:1939:10)
at Parser.pp$1.parseDecorators (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:1924:26)
at Parser.pp$1.parseStatement (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:1818:10)
at Parser.parseStatement (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:5910:22)
at Parser.pp$1.parseBlockBody (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:2268:21)
at Parser.pp$1.parseTopLevel (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:1778:8)
at Parser.parse (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:1673:17)
at parse (B:\Projekte\sketches\electron-react-get-
started\node_modules\babylon\lib\index.js:7305:37)
正如我在问题中所述,我通过“electron-prebuilt-compile”包运行编译内容。直到现在它派上用场并且运行良好。
这个包的 npm 页面说它的编译是由“电子编译”授权的。 电子编译适用于 JS ES6/ES7(通过 Babel),如他们的 github page,是什么让我想知道为什么我会遇到这个“装饰器”问题,因为 ES6 或至少 ES7 带有这个特性。 查看编辑
有关如何修复此错误的任何建议? Electron-prebuilt-compile 不允许我配置 webpack.config。 也许我必须自己设置 webpack?如果这样做,如何与电子结合?
编辑
正如 estus 在他的回答中所说:ES6 不包含装饰器,但“babel-plugin-transform-decorators-legacy”包含。
【问题讨论】:
标签: reactjs webpack ecmascript-6 electron decorator