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;
}
相关推荐
OpenTiny社区40 分钟前
当 AI 开始写 UI,我们缺的不是模型,是"设计词汇"
前端·github·ai编程
Amos_Web1 小时前
Rspack 源码解析(三十八):SubresourceIntegrityPlugin 如何跨四个插件协作生成 integrity
前端
Amos_Web2 小时前
通过 Rspack 源码学 Rust(八):struct 保存数据,impl 定义怎样使用数据
前端
anyup2 小时前
2027 年初,uni-app App 端停更倒计时,老项目该何去何从?
前端·vue.js·uni-app
JudithHuang4 小时前
Vue3 Vitest 单元测试进阶
前端·单元测试·log4j·vue
费曼学习法4 小时前
把 Agent 可观测性做进 Harness:从日志里只有 task finished 到全链路回放
前端
GuWenyue4 小时前
z-index 写到 9999 还是被盖住:把层叠上下文的 6 个反例全复现了一遍
前端·css·浏览器
htzyl2064 小时前
TypeScript:tsconfig配置误区及详情介绍,让你清清楚楚
前端·typescript
不服老的小黑哥4 小时前
0b · M2:服务化 + SSE 流式
前端
梦曦i4 小时前
0.9.0 新增页面级 style 支持
前端·uni-app x