Support for the experimental syntax 'decorators-legacy' isn't currently enabled (3:5):

React 导入 mobx 运行项目时出现了错误,符号 " @ "无法转译

Support for the experimental syntax 'decorators-legacy' isn't currently enabled (3:5):_第1张图片

上网查了些解决办法,主要分为以下几步:

1.git add .

 

2.git commit -am "Save" 

Support for the experimental syntax 'decorators-legacy' isn't currently enabled (3:5):_第2张图片

3.npm run eject

(必须要先执行上面两步,不然会报错。执行这步作用就是把之前的默认配置全部暴露出来,因此可以自定义修改webpack的配置)

4.npm install --save-dev babel-plugin-transform-decorators-legacy

5.npm install --save-dev @babel/plugin-proposal-decorators

6.npm install --save-dev @babel/plugin-proposal-class-properties

7.最后在 package.json 里修改 babel 如下所示

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

你可能感兴趣的:(React)