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;
}
相关推荐
问心无愧05137 小时前
ctf show web入门110
前端·笔记
拉拉肥_King7 小时前
Vue 3 主题切换深度解析:从炫酷动画到零闪烁方案
前端·vue.js
没事别瞎琢磨7 小时前
十、统一 Runner 入口——能力检测与模式回退
人工智能·node.js
excel7 小时前
为什么 Pinia + localForage 持久化后,页面初始化拿不到数据?
前端
雨雨雨雨雨别下啦7 小时前
vant介绍
前端
小小小小宇7 小时前
大模型失忆问题探讨
前端
wordbaby7 小时前
rn-cross-calendar:一个兼容 React 18/19、RN/RNOH 的跨平台日历组件
前端·react native·harmonyos
没事别瞎琢磨7 小时前
八、环境隔离——构建安全的子进程环境
人工智能·node.js
weixin_523185327 小时前
Collections.unmodifiableMap详解:真的不可修改吗?
java·linux·前端
江米小枣tonylua7 小时前
关掉 VSCode:在 NeoVim12 上配置 Claude Code
前端·程序员