gpt4 book ai didi

javascript - ./src/components/Main.jsx 中的错误 - Webpack

转载 作者:行者123 更新时间:2023-12-03 06:30:17 26 4
gpt4 key购买 nike

有人可以帮我吗?当我尝试使用 webpack 时,它向我显示以下错误:

Module build failed: SyntaxError: /path/to/my/folder/src/components/Main.jsx: Unexpected token (170:13)
168 |ReactDOM.render(
169 |<TodoApp
> 170 | todos={...store.getState()}
| ^
171 | />,
172 | document.getElementById('app')
173 | );

这是我的 webpack.config.js 的配置:

  module : {
loaders : [
{
test : /\.jsx$/,
exclude : /node_modules/,
loader : 'babel',
query : {
presets : ['react', 'es2015', 'stage-2']
}
}
]
}

有人可以帮我解决这个问题吗?

最佳答案

在 JSX 中,{} 是一个 JavaScript 表达式。由于您尝试传递对象文字,因此需要使用双括号:

todos={{...store.getState()}}

JSX Expression Docs

正如 david 下面指出的,如果您的目的只是将状态分配给 todos 而不添加您自己的任何属性,那么这就足够了:

todos={store.getState()}

关于javascript - ./src/components/Main.jsx 中的错误 - Webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38479362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com