Motion (Animation Library)
Motion, formerly known as Framer Motion, is a robust and highly performant open-source animation library designed for modern web development, offering first-class support for React, vanilla JavaScript, and Vue (via the separate `motion-v` package). As of version 12.38.0, it provides a simple yet powerful API for creating 120fps, GPU-accelerated animations using a hybrid engine that intelligently combines JavaScript capabilities with native browser APIs. The library maintains an active and frequent release cadence, with updates often published weekly or bi-weekly. Key differentiators include its comprehensive suite of "batteries-included" features, such as declarative gestures (drag, tap, hover), spring physics, advanced layout transitions for shared elements, scroll-linked effects, and complex timeline orchestrations. Motion is production-ready, featuring TypeScript support, tree-shakability, a tiny footprint, and an extensive test suite, making it a reliable choice for building fluid and interactive user interfaces across various platforms.
Common errors
-
Cannot find module 'framer-motion' or its corresponding type declarations.
cause The package `framer-motion` has been rebranded to `motion`.fixUninstall `framer-motion` and install `motion` (`npm install motion`). Update all import paths from `framer-motion` to `motion/react`. -
`motion.div` is not a function or `motion` is undefined.
cause Incorrect import path for Motion's React components, or attempting to use React-specific features from the vanilla JS import.fixFor React components, ensure you are importing `motion` from the correct subpath: `import { motion } from 'motion/react'`. -
Uncaught Error: A MotionValue can only be bound to a single component.
cause Attempting to pass a `MotionValue` instance (often created with `useMotionValue`) to multiple `motion` components, which is not supported as `MotionValue`s manage state for a single animated property on one component.fixEach `motion` component or property that needs an independent `MotionValue` should have its own instance. Re-evaluate your component tree to ensure `MotionValue`s are not shared across props where independent animation is expected. -
TS2307: Cannot find module '@emotion/is-prop-valid' or its corresponding type declarations.
cause The `@emotion/is-prop-valid` peer dependency or its types are not installed.fixInstall the missing dependency: `npm install @emotion/is-prop-valid` or `yarn add @emotion/is-prop-valid`.
Warnings
- breaking The package has been rebranded from `framer-motion` to `motion`. Existing projects must uninstall `framer-motion` and install `motion`, then update all import paths from `framer-motion` to `motion/react` for React components. The old package is no longer actively developed.
- breaking Major versions of Framer Motion (e.g., v3.0) included specific breaking changes related to velocity calculation, render scheduling, and `AnimatePresence` behavior. While the current `motion` package is at v12+, be mindful of detailed upgrade guides when moving between significant versions.
- gotcha The `motion` package now serves multiple platforms (React, vanilla JS, Vue via `motion-v`). Ensure you are using the correct import path for your environment (`motion/react` for React, `motion` for vanilla JS) to avoid errors or unintended behavior.
- gotcha Motion has a peer dependency on `@emotion/is-prop-valid`. While package managers often handle peer dependencies, you might encounter 'Module not found' warnings or errors if this dependency is not explicitly installed or if your build setup is unusual (e.g., in some monorepo configurations or older bundlers).
Install
-
npm install framer-motion -
yarn add framer-motion -
pnpm add framer-motion
Imports
- motion
import { motion } from 'framer-motion'import { motion } from 'motion/react' - animate
import { animate } from 'motion/react'import { animate } from 'motion' - AnimatePresence
import { AnimatePresence } from 'framer-motion'import { AnimatePresence } from 'motion/react'
Quickstart
import React from 'react';
import { motion } from 'motion/react';
function AnimatedBox() {
return (
<motion.div
initial={{ opacity: 0, x: -100 }}
animate={{ opacity: 1, x: 0 }}
transition={{
duration: 0.8,
delay: 0.2,
ease: [0, 0.71, 0.2, 1.01]
}}
style={{
width: '100px',
height: '100px',
backgroundColor: '#61dafb',
borderRadius: '10px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
fontSize: '1.2rem',
color: 'white',
cursor: 'pointer'
}}
whileHover={{ scale: 1.1, backgroundColor: '#282c34' }}
whileTap={{ scale: 0.9 }}
>
Hello Motion!
</motion.div>
);
}
export default AnimatedBox;