npm run start启动时提示 A decorated export must export a class declaration报错

问题描述:

基于react开发的项目在启动过程中,提示 A decorated export must export a class declaration报错,如下图所示:

npm run start启动时提示 A decorated export must export a class declaration报错_第1张图片

解决办法:

上面是一个react hoc高阶组件,es6装饰器的语法是要包裹class组件的,所以要改成以下这种写法就ok了;

export default function WithOperateTab(WrappedComponent) {
  @withRouter
  @withAliveScope
  class WrapperComponent extends PureComponent {
    openTab = (url) => {
      if (url) {
        const { tabKey } = getKeyName(url)
        this.props.history.push(url)
        setTimeout(() => {
          const cachingNodes = this.props.getCachingNodes(tabKey)
          if (cachingNodes.find((item) => item.cacheKey === tabKey)) {
            this.props.refresh(tabKey)
          }
        }, 100)
      }
    }
  }

  return WrapperComponent;
}

你可能感兴趣的:(npm,前端,node.js)