Next.js Discord

Discord Forum

FRAMER-MOTION NEXT JS

Unanswered
Tan posted this in #help-forum
Open in Discord
TanOP
Hello Friend.
I have a problem about my code. I’m having an issue with framer-motion.

ServicePageClient.tsx:
"use client"

import { services } from "@/data/services"
import ServiceCard from "@/components/ui/ServiceCard"
import { motion } from "framer-motion"

export default function ServicesPageClient() {
  // Animation variants
  const container = {
    hidden: { opacity: 0 },
    show: {
      opacity: 1,
      transition: {
        staggerChildren: 0.1,
      },
    },
  }

  const item = {
    hidden: { opacity: 0, y: 20 },
    show: { opacity: 1, y: 0, transition: { duration: 0.5 } },
  }

  return (
    <section className="py-16">
      <div className="max-w-3xl mx-auto text-center mb-16">
        <h1 className="text-4xl font-bold mb-6">Our Services</h1>
        <p className="text-lg text-gray-600">
          We offer a full range of digital services to help you grow your online presence and achieve your business goals.
        </p>
      </div>

      <motion.div
        variants={container}
        initial="hidden"
        animate="show"
        className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"
      >
        {services.map((service) => (
          <motion.div key={service.id} variants={item}>
            <ServiceCard title={service.title} description={service.description} icon={service.icon} />
          </motion.div>
        ))}
      </motion.div>
    </section>
  )
}

I’m getting an error on this line:

className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"

2 Replies

TanOP
Here’s the English translation of the error message:

Type '{ children: Element[]; variants: { hidden: { opacity: number; }; show: { opacity: number; transition: { staggerChildren: number; }; }; }; initial: string; animate: string; className: string; }' cannot be assigned to type 'IntrinsicAttributes & HTMLAttributesWithoutMotionProps<unknown, unknown> & MotionProps & RefAttributes<unknown>'.
  The property 'className' does not exist on type 'IntrinsicAttributes & HTMLAttributesWithoutMotionProps<unknown, unknown> & MotionProps & RefAttributes<unknown>'. ts(2322)
TanOP
I just resolved an issue I was having with framer-motion, and I think it could help others in the same situation.

Problem:
When I ran the command npm install framer-motion, the installed version was 10.x.x. However, this version is now obsolete and has compatibility issues with certain features (for example, using className on motion.div).

Solution:

First, I uninstalled the outdated version using the following command:
npm uninstall framer-motion --legacy-peer-deps


Then, I installed a newer and stable version. The latest version available as of January 2025 is 12.x.x, but it’s still in beta. To avoid potential bugs related to an unstable version, I recommend installing the previous version (11.18.2), which works very well for me:

npm install framer-motion@11.18.2 --legacy-peer-deps


Result:
After this update, the issue was resolved, and everything is working correctly.

Additional Tips:

If you’re using a preliminary version of React (such as React 19), you can test the alpha version of framer-motion (12.0.0-alpha.1), but be cautious as it may be unstable.
Also, make sure your versions of react and next.js are up to date to ensure good compatibility.