React project - spread operator in node module unexpected token

╄→гoц情女王★ 提交于 2021-02-16 16:21:07

问题


I'm building a react application, and I'm importing a node module which uses the spread operator ... and I'm getting an error "Module parse failed: Unexpected token (100:6)" at this operator. How can I get this to work?

Thanks


回答1:


The create-react-app cli has already bundled this ES2015 feature. Older babel does not support this and needs to be installed separately

Now assuming you setup your react manually and not using the create-react-app. You can set up this by installing the package babel-plugin-transform-es2015-spread or babel-plugin-transform-object-rest-spread

Here is the step to work with this

npm install --save-dev babel-plugin-transform-es2015-spread

Now open your .babelrc and declare the plugin

{
  "plugins": ["transform-es2015-spread"]
}

Possible Duplicate : Spread Operator not working for Redux/ES6 based sample



来源:https://stackoverflow.com/questions/51778230/react-project-spread-operator-in-node-module-unexpected-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!