question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Framer Motion v4 breaks Chakra

See original GitHub issue

🐛 Bug report

💥 Steps to reproduce

  1. Install a fresh instance of Chakra, including all of its required dependencies
  2. Start the app
  3. Notice it crash

💻 Link to reproduction

CodeSandbox reproduction: https://codesandbox.io/s/chakra-framer-motion-v4-bug-4i6rq

📝 Additional information

Looking at the Framer Motion changelog, it appears to be related to the deprecation of motion.custom() in favor of motion(), which I believe is being tracked in #3459 .

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:35
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
philipguedescommented, Mar 18, 2021

Same here, just installed Chakra in a new Nextjs project and got the same error

TypeError: _framerMotion.motion.custom is not a function
    at Object.<anonymous> (/node_modules/@chakra-ui/checkbox/dist/cjs/checkbox-icon.js:20:38)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)

Downgraded framer-motion to v3.10.6 and it solved the problem for me

17reactions
with-heartcommented, Mar 19, 2021

The main thing I’ve been worried about in trying to resolve this situation for us is maintaining our commitment to semantic versioning. For a bit there, I was worrying that we had dug ourselves into a hole that we couldn’t get out of, because forcing users to 4.0.0 would need to be considered a breaking change since framer-motion is a peerDependency.

However, I think that worry was incorrect. Our peerDependency range already supports framer-motion@4.0.0 (because >=3.0.0), it’s just that our codebase doesn’t support it. Since we’re not removing ^3.0.0 from this range, it’s not a breaking change on our part, just a minor change that adds support for framer-motion@^4.0.0 to the codebase.

Here’s what the changes that will be part of this minor bump will consist of:

Conditional checks to support both v3 and v4 APIs

We can determine whether we’re in v3 or v4 based on the existence of motion.custom:

const v3 = 'custom' in motion
const v4 = !('custom' in motion)

We can use this to add conditionals throughout the codebase in order to support both version:

  • Conditionally call motion or motion.custom based on whether motion.custom exists:
const MotionSvg =
  'custom' in motion ? (motion as any).custom(chakra.svg) : motion(chakra.svg)
  • Bump devDependencies versions of framer-motion from ^3.1.1 to ^4.0.0. Without this, we can’t track changes to the v4 API and update our internals as necessary.

Future-proofing

  • Reduce peerDependency range of framer-motion to 3.x || 4.x, so we can avoid this situation in the future with framer-motion@5 😬
  • Update installation instructions to install framer-motion@^4 so that fresh Chakra installs use the current latest version. Since we’ll eventually drop 3.0 support to take full advantage of the new bundle size reduction stuff in 4.0, this will make it easier for new installs to upgrade when that inevitably happens.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chakra UI + Framer Motion
This example shows how to add some interesting motion interaction or animation to your Chakra UI websites or apps with Framer Motion.
Read more >
npm chakra-ui install failing due to dependency conflicts
I'm trying to learn react/typescript and I'm following a tutorial line for line, but somehow getting this error when trying to install either...
Read more >
Accessibility | Framer for Developers
How to design accessible animations with Framer Motion. Animations can have serious usability implications, even inducing motion sickness in some people.
Read more >
Page Loading Progress with Next.js and Chakra UI - Tealfeed
Install Chakra UI by running this command: yarn add @chakra-ui/react '@emotion/react@^11' '@emotion/styled@^11' 'framer-motion@^4'. For Chakra UI to work ...
Read more >
Problem with Chakra UI modal component : r/reactjs - Reddit
I followed u/linebreaking tip for upgrading "framer-motion" library to the latest and it worked. Was using 4.0.0 and there wasn't any breaking ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found