问题
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