You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qwik 1.0.0中Lottie/Rive报错'useClientEffectQrl is not a function'求助

Qwik 1.0.0中使用Qwik Lottie/Rive报错"useClientEffectQrl is not a function"的解决方案

问题原因

Qwik 1.0.0对客户端生命周期API进行了重大迭代,原有的useClientEffectQrl API已被移除,替换为useClientEffect$。而当前版本的qwik-lottie及Rive的Qwik绑定库仍依赖旧版API,导致与Qwik 1.0.0不兼容,触发该错误。

解决方案

方案一:降级Qwik到0.x兼容版本(项目允许的情况下)

通过降级Qwik核心包匹配第三方库的API要求:

npm install @builder.io/qwik@^0.100.0 @builder.io/qwik-city@^0.100.0

注意:降级后需同步检查项目其他依赖是否适配Qwik 0.x版本。

方案二:直接集成原生Lottie/Rive库替代第三方Qwik绑定

以Lottie为例,手动接入官方原生库lottie-web:

  1. 安装依赖
npm install lottie-web
  1. 修改组件代码,使用Qwik 1.0.0的useClientEffect$初始化动画
import { component$, useStore, useClientEffect$, useRef$ } from '@builder.io/qwik';
import type { DocumentHead } from '@builder.io/qwik-city';
import lottie from 'lottie-web';

export default component$(() => {
  const containerRef = useRef$<HTMLDivElement>();
  const store = useStore({
    options: {
      path: 'https://assets7.lottiefiles.com/packages/lf20_M6jA5UNDHa.json',
    },
  });

  useClientEffect$(() => {
    if (containerRef.current) {
      lottie.loadAnimation({
        container: containerRef.current,
        renderer: 'svg',
        loop: true,
        autoplay: true,
        path: store.options.path,
      });
    }
  });

  return (
    <body>
      <div class={"smallScreen"}>
        <div ref={containerRef}></div>
        <div class={"fixed min-h-20 bg-purple-800 w-full bottom-0 p-2"}>
          <div class={"flex flex-col"}>
            <div class={"flex justify-center w-full"}>
              <img 
                class={"w-14 mb-1"}
                src="https://cmjanshikayat.cgstate.gov.in/landing-page-assest/assets/images/chips.jpg" alt="chips logo"/>
            </div>
            <div class={"select-none text-center font-normal text-white text-xs"}>वेबसाइट प्रबंधन कार्य छत्तीसगढ़ इन्फोटेक प्रमोशन सोसायटी, इलेक्ट्रॉनिक्स एवं सूचना प्रौद्योगिकी विभाग, छत्तीसगढ़ शासन द्वारा किया जा रहा है।</div>
            <div class={"select-none text-center font-normal text-white text-xs"}>कॉपीराईट © 2022 <a href="https://chips.gov.in/" class={"font-semibold text-xxs"}>CHiPS</a></div>
          </div>
        </div>
      </div>
    </body>
  );
});

export const head: DocumentHead = {
  title: 'Test',
  meta: [
    {
      name: 'description',
      content: 'Test description',
    },
  ],
};

此方式绕过第三方绑定库,直接使用官方原生库,不仅兼容性更强,还能自定义更多动画配置项。

方案三:等待第三方库适配Qwik 1.0

关注qwik-lottie及Rive Qwik绑定库的官方仓库或npm页面,等待发布兼容Qwik 1.0.0的版本后再升级使用。

验证

执行npm run dev重启项目,检查动画是否正常加载,确认错误是否消失。

内容的提问来源于stack exchange,提问作者Rishabh nayak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 07:52:51