我有 Next.js 项目,我在其中使用 lottie-player 来制作一些动画图标。但是,每次运行该项目时我都会收到以下错误。一旦错误被关闭,应用程序就可以正常运行。
NotSupportedError:无法在“CustomElementRegistry”上执行“define”:名称“lottie-player”已在此注册表中使用。我究竟做错了什么?
我已经安装了 Lottie 播放器,并且正在使用 useEffect 导入 Lottie 播放器:
useEffect(() => {
import("@lottiefiles/lottie-player");
});
Run Code Online (Sandbox Code Playgroud)
然后使用这些图标:
<><script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js" async>. </script>
<lottie-player src="https://assets5.lottiefiles.com/packages/lf20_YIBaBZH9fj.json" background="transparent" speed="0.5" style={{ "width": "200px", "height": "150px" }} loop autoplay></lottie-player>
</>
Run Code Online (Sandbox Code Playgroud)