【问题标题】:using webpack to compile redux example todos,but exists error [duplicate]使用 webpack 编译 redux 示例 todos,但存在错误 [重复]
【发布时间】:2018-03-21 10:06:09
【问题描述】:

这会存在error:ERROR in ./src/reducers/todos.js 模块构建失败:SyntaxError: Unexpected token (15:13)

案例“TOGGLE_TODO”:

  return state.map(todo =>
    (todo.id === action.id)
      ? {...todo, completed: !todo.completed}
         ^(error here)
      : todo
  )

案例“TOGGLE_TODO”:

  return state.map(todo =>
    (todo.id === action.id)
      ? Object.assign({}, todo, {completed: !todo.completed})
      : todo
  )

但是改成最后一个代码会成功,我想知道为什么第一个代码不能编译成功。感谢任何帮助!

【问题讨论】:

  • 我已经添加代码并指出错误位置,感谢任何帮助,谢谢!
  • 谢谢大家,非常感谢您的帮助,非常感谢

标签: reactjs webpack redux


【解决方案1】:

请检查您是否设置了 babel 以支持 Object Spread Operator。 查看 Redux 文档的此页面以供参考: https://redux.js.org/recipes/using-object-spread-operator

【讨论】:

  • 非常感谢,我已经解决了问题。
  • 对于其他人:如果你有同样的问题,运行 npm install --save-dev babel-plugin-transform-object-rest-spread,并创建一个 .babelrc add { "presets": [ "env"], "plugins": ["transform-object-rest-spread"] }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-31
  • 2017-08-21
  • 2018-08-25
  • 1970-01-01
  • 2016-10-20
  • 2018-08-23
  • 2021-10-26
相关资源
最近更新 更多