-
-
Notifications
You must be signed in to change notification settings - Fork 806
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
node_modules\lottie-web\build\player\lottie.js (30:0) @ createTag ⨯ ReferenceError: document is not defined #47
Comments
What is the fix for this? |
nvm i figured out what was happening. the components need to be imported dynamically in page.js:
|
In my case I didn't want to have to use a client component for the whole page, so I just ended up dynamically importing the AnimationLottie component in Experience and Education: const AnimationLottie = dynamic<AnimationLottieProps>(
() =>
import("../../helper/animation-lottie").then((mod) => mod.AnimationLottie),
{ ssr: false },
); And exporting AnimationLottie like this: "use client"
import Lottie from "lottie-react";
export interface AnimationLottieProps {
animationPath: Record<string, unknown>;
};
export const AnimationLottie = ({ animationPath }: AnimationLottieProps) => {
const defaultOptions = {
loop: true,
autoplay: true,
animationData: animationPath,
style: {
width: '95%',
}
};
return (
<Lottie {...defaultOptions} />
);
}; |
How i fixed my issue: Step 1: Separate Client-Side Components Create a new file ClientHome.jsx in the app/ directory (or an appropriate folder) to handle all client-side rendering. Result: This file handles server-side logic, such as fetching data (getData). The new ClientHome.jsx is marked as a client component with "use client";. Dynamically imported components (HeroSection, Experience, etc.) are rendered only on the client. |
▲ Next.js 14.1.3
✓ Ready in 4.3s
○ Compiling / ...
✓ Compiled / in 12.7s (1100 modules)
⨯ node_modules\lottie-web\build\player\lottie.js (30:0) @ createTag
⨯ ReferenceError: document is not defined
at webpack_require (C:\Users\NIshanth\Desktop\New folder\portfolio.next\server\webpack-runtime.js:33:43)
at webpack_require (C:\Users\NIshanth\Desktop\New folder\portfolio.next\server\webpack-runtime.js:33:43)
at eval (./app/components/helper/animation-lottie.jsx:7:70)
at (ssr)/./app/components/helper/animation-lottie.jsx (C:\Users\NIshanth\Desktop\New folder\portfolio.next\server\app\page.js:272:1)
at webpack_require (C:\Users\NIshanth\Desktop\New folder\portfolio.next\server\webpack-runtime.js:33:43)
null
✓ Compiled in 2.3s (447 modules)
○ Compiling /favicon.ico ...
✓ Compiled /favicon.ico in 844ms (682 modules)
The text was updated successfully, but these errors were encountered: