[英]Unable to compile JSX using web-pack with babel loader
我正在尝试使用 web-pack 捆绑一个 react 应用程序,该应用程序使用 babel 加载器来编译因语法错误而失败的 jsx 文件。
handleClick = () => {
this.props.handleFixedClick();
};
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (37:14)
35 | }
36 |
> 37 | handleClick = () => {
| ^
38 | this.props.handleFixedClick();
39 | };
40 |
我尝试将 babel-loader 版本更改为 7.15,但没有任何努力。 以下是我的 web-pack.config.js。
test: /\.jsx?/,
loader: 'babel-loader',
exclude: /node_modules/,
query:{
presets: ['react','es2015']
}
以下是我的 package.json
"@babel/core": "^7.5.5",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
要使用类属性语法(例如类中的 lambdas),您还需要 babel 插件@babel/plugin-proposal-class-properties
使用npm install --save-dev @babel/plugin-proposal-class-properties
安装它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.