Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readReact

Move from framer-motion to motion/react

Replace framer-motion with the motion package, update React imports, and check your existing animation entry points after the migration.

If your React app uses framer-motion, install motion and switch your React imports to motion/react in the same change.

Swap the dependency in the app

Run the package commands in the app that owns the animation code. The example uses Motion 12. If the app uses an older major of Framer Motion, check the upgrade guide for the majors you cross before you combine the changes.

npm uninstall framer-motion
npm install motion@12

You should see motion listed in the app's dependencies and the old direct dependency removed.

In a workspace, check shared animation components as well as the app. A wrapper package that imports from framer-motion has its own dependency to migrate. Search for the old name in source files, test mocks and re-exports. A copy of the old name in a lockfile can come from a dependency of another package, so inspect the import sites before removing anything else.

Move your React imports

Change each React import's module specifier to motion/react. Keep names such as motion and AnimatePresence on the import and leave their props alone while you make the swap. You can check the new entry point with this small badge.mjs file in a project that has React and React DOM.

import { createElement as h } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { motion } from 'motion/react'

const badge = h(motion.span, {
  initial: { opacity: 0 },
  animate: { opacity: 1 },
}, 'Saved')

console.log(renderToStaticMarkup(badge))

Run node badge.mjs and you should see a span with style="opacity:0" and the text Saved.

That smoke check exercises the import and initial markup. Open a screen in your app and trigger an entrance and an exit. If an item disappears without its exit animation, check that it is still under AnimatePresence and that you migrated both imports.

If the build reports that it cannot resolve motion/react, check that motion is installed in the package that imports it. For an animation behind a shared wrapper, test the wrapper from one of its consumers. Then run the app's production build to catch any old import that only appears in a route you skipped.