Client/Server Components Rendering with Framer Motion
Answered
Bigheaded ant posted this in #help-forum
Bigheaded antOP
I am having a really bad time learning Next.js 13 in those client/server component new (i think) stuff, i am trying to build a app that uses framer-motion to animate some components as showed in the screenshot above
Answered by Bigheaded ant
Solution: Framer Motion components only render when they are a child of a client component, soo if you are planning to animate the main div of your page, you are mostly like to client render the whole page
24 Replies
Bigheaded antOP
full error report:
Failed to compile
This error occurred during the build process and can only be dismissed by fixing the error.
Failed to compile
./node_modules\framer-motion\dist\es\animation\hooks\use-animated-state.mjs
ReactServerComponentsError:
You're importing a component that needs useEffect. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Learn more: https://nextjs.org/docs/getting-started/react-essentials
,-[C:\Users\val_m\Documents\GitRepos\nextjs-slottracker\node_modules\framer-motion\dist\es\animation\hooks\use-animated-state.mjs:1:1]
1 | import { useState, useEffect } from 'react';
: ^^^^^^^^^
2 | import { useConstant } from '../../utils/use-constant.mjs';
3 | import { getOrigin, checkTargetForNewValues } from '../../render/utils/setters.mjs';
4 | import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
`----
Maybe one of these should be marked as a client entry with "use client":
./node_modules\framer-motion\dist\es\animation\hooks\use-animated-state.mjs
./node_modules\framer-motion\dist\es\index.mjs
./src\app\Components\Pages\Main\Loading.tsx
./src\app\page.tsxThis error occurred during the build process and can only be dismissed by fixing the error.

Dwarf Crocodile
try "use client" on top of the code?
@Dwarf Crocodile try "use client" on top of the code?
Silver Marten
looks like the problem is coming from within the framer-motion library. I suggested him deep diving into the node_module files and add "use client" but deleted it bc idk if it's a good idea.
@Bigheaded ant look at the github and check on the progress of them adding client/server components into the library
@Silver Marten looks like the problem is coming from within the framer-motion library. I suggested him deep diving into the node_module files and add "use client" but deleted it bc idk if it's a good idea.
European sprat
No need to do this when you could just create a new client component that wraps the issue component
Silver Marten
im no expert by all means, but wouldn't that mean you're wrapping a server component inside a client component
@European sprat No need to do this when you could just create a new client component that wraps the issue component
Bigheaded antOP
a child client component just to fix this issue?
@Dwarf Crocodile try "use client" on top of the code?
Bigheaded antOP
already did it
European sprat
I don't know I was just indicating that if the issue is a library component that doesn't have use client and needs it you could wrap it in your own use client component rather than trying to edit something in node modules
Dwarf Crocodile
oh try older versions
i dont have more ideaxd
Bigheaded antOP
i will just stand by framer-motion components for now then, the main porpuse of this project is to learn next 13 features
@Bigheaded ant i will just stand by framer-motion components for now then, the main porpuse of this project is to learn next 13 features
Bigheaded antOP
soo using a older next is not a option right now
Silver Marten
wrap motion.button inside a client component then import that wrapped component to your loading.tsx passing in the necessary props
Bigheaded antOP
yeah, i just did it
its kinda messy to plan the UI doing that
because animating a lot of components means to use client component on top of everything
Silver Marten
im sure framer motion will compatibility soon, just look out for updates, sorry about the confusion earlier.
@Bigheaded ant its kinda messy to plan the UI doing that
Silver Marten
:((
Bigheaded antOP
no problem, i am here to learn
@Bigheaded ant no problem, i am here to learn
Silver Marten
don't worry me to xd
Bigheaded antOP
Solution: Framer Motion components only render when they are a child of a client component, soo if you are planning to animate the main div of your page, you are mostly like to client render the whole page
Answer