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

问题描述:

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

解决办法:

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

javascript 复制代码
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;
}
相关推荐
广州华水科技20 分钟前
水库的单北斗GNSS变形监测系统是什么?主要有哪些应用?
前端
薛一半21 分钟前
React三大属性之props
前端·javascript·react.js
Wect1 小时前
LeetCode 105. 从前序与中序遍历序列构造二叉树:题解与思路解析
前端·算法·typescript
烤麻辣烫1 小时前
正则表达式快速掌握
前端·javascript·学习·正则表达式·html
长城20241 小时前
HTML5中可以省略属性值的11个属性总结
前端·html·html5·属性值·省略属性值
木斯佳1 小时前
前端八股文面经大全:小红书前端一面(2026-2-3)·面经深度解析
前端·状态模式
心之语歌2 小时前
flutter 父子组件互相调用方法,值更新
前端·javascript·flutter
岱宗夫up3 小时前
FastAPI进阶3:云原生架构与DevOps最佳实践
前端·python·云原生·架构·前端框架·fastapi·devops
赛博切图仔3 小时前
告别“打字机”:Generative UI 如何重塑 AI 时代的前端交互?
前端·人工智能·ui
wangbing11253 小时前
开发指南141-类和字节数组转换
java·服务器·前端