关于报错Support for the experimental syntax 'decorators-legacy' isn't currently enabled

报错原因

装饰器写法不被支持

解决办法

bable转码

npm install @babel/plugin-proposal-decorators

配置package.json
  "babel": {
    "plugins": [
      [
        "@babel/plugin-proposal-decorators",
        {
          "legacy": true
        }
      ]
    ],
    "presets": [
      "react-app"
    ]
  },

发现直接写在package.json中不管用,
需要先
git add .
接着
git commit -m 'init'
最后
npm run eject
之后再把

 "babel": {
   "plugins": [
     [
       "@babel/plugin-proposal-decorators",
       {
         "legacy": true
       }
     ]
   ],
   "presets": [
     "react-app"
   ]
 },

写在package.json中

你可能感兴趣的:(react)