React Project-节点模块中的扩展运算符意外令牌 [英] React project - spread operator in node module unexpected token
问题描述
我正在构建一个React应用程序,并且正在导入一个使用扩展运算符 ...
的节点模块,但出现错误模块解析失败:意外令牌(100:6)".我怎样才能使它正常工作?
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?
谢谢
推荐答案
create-react-app cli已捆绑了此ES2015功能.较早的babel不支持此功能,需要单独安装
The create-react-app cli has already bundled this ES2015 feature. Older babel does not support this and needs to be installed separately
现在,假设您手动设置了反应,而不使用create-react-app.您可以通过安装软件包进行设置 babel-plugin-transform-es2015-spread 或者 babel-plugin-transform-object-rest-spread
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
这是与此相关的步骤
npm install --save-dev babel-plugin-transform-es2015-spread
现在打开您的.babelrc并声明插件
Now open your .babelrc and declare the plugin
{
"plugins": ["transform-es2015-spread"]
}
可能重复: Spread运算符不适用于Redux/ES6基础样本
这篇关于React Project-节点模块中的扩展运算符意外令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!