Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: document is not defined at createTag (node >18) #149

Open
1 task
zifeo opened this issue Nov 30, 2023 · 10 comments
Open
1 task

ReferenceError: document is not defined at createTag (node >18) #149

zifeo opened this issue Nov 30, 2023 · 10 comments

Comments

@zifeo
Copy link

zifeo commented Nov 30, 2023

Overview

Using NextJS, we got:

Error occurred prerendering page "/X". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined at createTag ...

This has been reported as a potential bug related to the node version: Gamote/lottie-react#101.

Consuming repo

What repo were you working in when this issue occurred?

# use node 20 or 21
npx create-next-app@latest
# edit app/page.ts
# add the Player component as demo

Labels

  • Add the Type: Bug label to this issue.
@daaavy-lazer-claw
Copy link

I'm getting the same error as well on latest node version. Switching to 18.18.2 fixed it for me.

@sonangrai
Copy link

sonangrai commented Jan 1, 2024

im getting this as well on node v20+

Screenshot 2024-01-01 at 6 09 49 PM

@dzungmv
Copy link

dzungmv commented Jan 5, 2024

Please 'use client' in component using this library.

[Nextjs] For me, I also separate animation lottie into single component with 'use client' in the top of file:
image

And import this to Server component by dynamic import:
image

Copy link

github-actions bot commented Mar 6, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the stale label Mar 6, 2024
@edwardoverthere
Copy link

This impacts more than just Next. I'm using this repo in a gatsby project am am running into the same issue.
Getting the error: ReferenceError: document is not defined

@github-actions github-actions bot removed the stale label May 15, 2024
@adrivelasco
Copy link

adrivelasco commented Jul 2, 2024

I confirm this error is gone if you dynamically import the Player component as @dzungmv suggested.

This is my solution.

// player.tsx
import dynamic from 'next/dynamic';

export const ReactLottiePlayer = dynamic(
  async () => {
    const ReactLottie = await import('@lottiefiles/react-lottie-player');
    return ReactLottie.Player;
  },
  { ssr: false }
);
// page.tsx
'use client';

import { ReactLottiePlayer } from '@/lib/lottiefiles/player';

export function Page() {
  return (
    <ReactLottiePlayer
      src="/animation.json"
      speed={1}
      loop
      autoplay
    />
  ); 
}

Tested in Next.js v14.x

@M-YasirGhaffar
Copy link

My Project was complex so dynamic import was not feasible solution. It works fine on node v18 though

Copy link

github-actions bot commented Sep 6, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the stale label Sep 6, 2024
@fl0wo
Copy link

fl0wo commented Nov 12, 2024

downgraded from node22 to node20

@github-actions github-actions bot removed the stale label Nov 13, 2024
@SapirBar2
Copy link

is there any solution for node v22?
I cannot use lazy loading..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants