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;
}
相关推荐
云和数据.ChenGuang几秒前
python 面向对象基础入门
开发语言·前端·python·django·flask
We་ct8 分钟前
LeetCode 202. 快乐数:题解+思路拆解
前端·算法·leetcode·typescript
HWL567910 分钟前
控制浏览器如何预先加载视频资源
java·服务器·前端
HWL567911 分钟前
在网页中实现WebM格式视频自动循环播放
前端·css·html·excel·音视频
嵌入式×边缘AI:打怪升级日志11 分钟前
从设备接收请求的状态机与超时机制
服务器·前端
鸡吃丸子12 分钟前
前端视角下的埋点:实操指南与避坑要点
前端
前端摸鱼匠13 分钟前
Vue 3 的ref在响应式对象中:介绍ref在reactive对象中的自动解包
前端·javascript·vue.js·前端框架·ecmascript
HWL567916 分钟前
防止移动设备自动全屏播放视频,让视频在页面内嵌位置正常播放
前端·css·音视频
Polaris_YJH17 分钟前
使用Vue3+Vite+Pinia+elementUI搭建初级企业级项目
前端·javascript·elementui·vue
菜鸟una18 分钟前
【微信小程序+Taro 3+NutUI 3】input (nut-input) 、 textarea (nut-texteare)类型使用避坑
前端·vue.js·微信小程序·小程序·taro