在过去的某个时候,React决定从其react-app预设中删除一些babel预设。我将旧项目中的“ babel-preset-react- app”(node_modules中的文件夹)与新创建的react应用(使用create-react-app v3.4创建)的babel- presets进行了比较。通过比较两个应用程序的babel-preset-react- app中的package.json,我发现在较新的版本中,安装的babel插件要少得多。
安装@ babel / plugin-proposal-object-rest-spread(也许还可以确定@ babel / plugin-transform-spread):
npm install @babel/plugin-proposal-object-rest-spread @babel/plugin-transform-spread
完成后,只需将它们作为插件添加到您的react应用程序的package.json中,即可从react导入的预设下面:
"babel": {
"presets": [ // This line should already be there if you created your project with CRA
"react-app"
],
"plugins": [
"@babel/plugin-transform-spread",
"@babel/plugin-proposal-object-rest-spread"
]
}
希望对您有所帮助!