React can't deconstruct restProps in Edge

后端 未结 1 1940
情书的邮戳
情书的邮戳 2021-01-16 15:35

I\'ve a problem and somehow I just can\'t solve it. I tried everything for hours but I just don\'t find a solution. It worked in older projects, but doesn\'t work with a bra

相关标签:
1条回答
  • 2021-01-16 15:47

    After searching for a while, I found a solution for the problem. It works without ejecting.

    The Problem & the way I found a solution:

    At some point in the past, react decided to remove some babel presets from their react-app presets. I compared the "babel-preset-react-app" (folder inside node_modules) from an older project, with the babel-presets from a newly created react app (created with create-react-app v3.4). By comparing the package.json from the babel-preset-react-app from both applications, I found out that in the newer version, there are much less babel plugins installed.

    The solution: Install the @babel/plugin-proposal-object-rest-spread (and maybe also the @babel/plugin-transform-spread just to be sure) by running:

    npm install @babel/plugin-proposal-object-rest-spread @babel/plugin-transform-spread
    

    Once done, simply add them as plugins inside the package.json of your react app, below the imported presets from 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"
        ]
      }
    

    I hope this helped!

    0 讨论(0)
提交回复
热议问题