lottie-react icon indicating copy to clipboard operation
lottie-react copied to clipboard

nextjs 15 cant import lottie-react in client components , ReferenceError: document is not defined

Open bloodykheeng opened this issue 8 months ago • 9 comments

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

bloodykheeng avatar Mar 19 '25 13:03 bloodykheeng

Happens on Next.js v14 on Node 22 as well

MacPiston avatar Mar 28 '25 08:03 MacPiston

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.

SiebeBaree avatar Apr 08 '25 07:04 SiebeBaree

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 avatar Apr 24 '25 16:04 mburmistrov

@mburmistrov Agree !

miayang0513 avatar May 02 '25 21:05 miayang0513

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

zacharytyhacz avatar May 12 '25 15:05 zacharytyhacz

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

Ludwintor avatar May 18 '25 05:05 Ludwintor

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"

Ludwintor avatar May 18 '25 05:05 Ludwintor

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.

mburmistrov avatar May 23 '25 09:05 mburmistrov

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.

Minho-Lee avatar Jun 11 '25 14:06 Minho-Lee