【问题标题】:Support for the experimental syntax 'decorators-legacy' isn't currently enabled当前未启用对实验性语法“decorators-legacy”的支持
【发布时间】:2018-11-23 04:30:03
【问题描述】:

我在使用 mobx-react 和尝试使用注释时遇到上述错误。这里我使用的是 .js 而不是 .ts。之前提供的所有解决方案对我来说都不成功。

import React, { Component } from 'react';
import { withRouter, Redirect } from 'react-router-dom';
import { observable, action } from 'mobx';
import { inject, observer } from 'mobx-react';

@inject('authStore')
@withRouter
@observer
class Login extends Component {

   componentWillUnmount() {
       this.props.authStore.reset();
   }

}

我的错误是

【问题讨论】:

标签: reactjs babeljs mobx mobx-react


【解决方案1】:

如果你使用的是 babel,那么你需要安装和使用 @babel/plugin-proposal-decorators 并启用 legacy 模式。

例如.babelrc的plugins部分:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-15
    • 2021-02-09
    • 2019-06-17
    • 1970-01-01
    • 2020-11-30
    • 2020-01-07
    • 2020-11-10
    相关资源
    最近更新 更多