美文网首页
Syntax error - Support for the e

Syntax error - Support for the e

作者: magic_pill | 来源:发表于2020-09-21 22:53 被阅读0次

    在 cra 中使用装饰器时报如下错误:

    Syntax error - Support for the experimental syntax 'decorators-legacy' isn't currently enabled

    首先安装依赖

    • npm i -D @babel/plugin-proposal-decorators babel-plugin-import customize-cra react-app-rewired

    根目录创建config-overrides.js

    const {
      override,
      fixBabelImports,
      addDecoratorsLegacy
    } = require("customize-cra");
    
    module.exports = override(
      fixBabelImports("import", {
        //antd按需加载
        libraryName: "antd",
        libraryDirectory: "es",
        style: "css"
      }),
      addDecoratorsLegacy() //配置装饰器
    );
    

    解决方案:在package.json中添加配置

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

    相关文章

      网友评论

          本文标题:Syntax error - Support for the e

          本文链接:https://www.haomeiwen.com/subject/cjzbyktx.html