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;
}
相关推荐
百结214几秒前
HAProxy 搭建 Web 集群
前端·web
GISer_Jing6 分钟前
Todos
前端·人工智能·学习
hresh8 分钟前
两个 Chrome 窗口各 20 多个 tab 后,我把 tab-out 改成了更顺手的 TabNest
前端·chrome·后端
invicinble8 分钟前
前端技术栈--vuecli页面固定思路解密,与vue-router技术栈信息
前端·javascript·vue.js
shadowcz00712 分钟前
CHI 2026 归来:AI/LLM 正在重写人机交互的底层语法
前端·人工智能·html·人机交互
Moment15 分钟前
面试官:LangChain中 TS 和 Python 版本有什么差别,什么时候选TS ❓❓❓
前端·javascript·后端
JarvanMo18 分钟前
SINT能否取代GetX?
前端
Mintopia20 分钟前
深入理解计算机架构:从硬件到软件的桥梁
前端
大尚来也20 分钟前
HTTPS的性能优化:从握手延迟到会话复用
前端
尘埃落定wf22 分钟前
LangChain AgentExecutor 完全指南:ReAct循环+Memory+LLM实战
前端·javascript·react.js