欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Support for the experimental syntax 'decorators-legacy' isn't currently enabled,装饰器语法报错

程序员文章站 2022-07-05 18:17:00
...

react 项目引入mobx之后,用到了装饰器这个语法,但是项目没有识别出来,运行项目报错,报错截图如下:

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

Support for the experimental syntax 'decorators-legacy' isn't currently enabled,装饰器语法报错
解决办法:
在项目的package.json文件中添加这么一段代码:
允许使用装饰器

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

Support for the experimental syntax 'decorators-legacy' isn't currently enabled,装饰器语法报错然后在运行,报错就会消失了。如果还是不行,可以重新安装下依赖,再启动下项目。问题基本就解决了。

相关标签: 前端问题总结