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;
}
相关推荐
excel几秒前
ES6 中函数的双重调用方式:fn() 与 fn\...``
前端
可乐爱宅着13 分钟前
全栈框架next.js入手指南
前端·next.js
你的人类朋友2 小时前
什么是API签名?
前端·后端·安全
会豪4 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子4 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶4 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子4 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_4 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_23334 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
RoyLin4 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js