设置React和Babel时,出现以下语法错误:
ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (5:8)
3 |
4 | const Index = () => {
> 5 | return <div>Hello React</div>;
| ^
6 | }
7 |
8 | ReactDOM.render(<Index />, document.getElementById("index"));
这与文章-“如何使用Webpack 4从头创建React应用”相关,该文章可在freeCodeCamp上找到...
有人也得到了吗?
谢谢!
答案 0 :(得分:0)
npm安装babel-loader babel-preset-react
添加此模块。 并在webpack配置中添加以下内容。
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel-loader",
query:
{
presets:['react']
}
}