lottie-react
lottie-react copied to clipboard
nextjs 15 cant import lottie-react in client components , ReferenceError: document is not defined
importing the package in next js use client components results intor that this error ReferenceError: document is not defined
import Lottie from "lottie-react";
please improve the package so that it runs in client only smoothly
without me needing to first do this
import dynamic from "next/dynamic";
const Lottie = dynamic(() => import("lottie-react"), { ssr: false });
am using react 19 nextjs 15
Happens on Next.js v14 on Node 22 as well
Happens to me as well (Next 15, React 19, Node 22). The next/dynamic solution works but now my component is not loaded in at mount so the animation appears in later, which is not suitable for my needs.
I believe the problem is with lottie-web https://github.com/airbnb/lottie-web/issues/3047, which lottie-react uses under the hood, not with lottie-react itself.
@mburmistrov Agree !
I keep seeing this error in my logs, but page and app runs fine. Just annoying to see this error fill up logs but still work
apparently this is issue with lottie-web and the most interesting part - this issue was fixed 1 year ago and merged into version 5.13.0 but release pipeline failed so the latest npm version still 5.12.2. After this maintainers just disappeared and the project renders to be dead
https://github.com/airbnb/lottie-web/pull/3133
Also I can recommend another fix to avoid using dynamic
You need to disable experimental global navigator from node, put .env file in project's root and paste this env
NODE_OPTIONS="--no-experimental-global-navigator"
Hi, lottie-web released v5.13.0, which seems to fix this issue. Make sure that at least this version of lottie-web is installed as a dependency of lottie-react, and everything should work.
Hi, lottie-web released v5.13.0, which seems to fix this issue. Make sure that at least this version of lottie-web is installed as a dependency of lottie-react, and everything should work.
Setting a resolution for lottie-web to 5.13.0 worked for me.