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.

Seems like framer-motion fallback does not work with webpack 5

See original GitHub issue

I have a pretty complex monorepo which I now just got working with Yarn 3 workspaces, webpack 5, craco and react-scripts. It’s been an absolute nightmare so far and when I though I got it working, Chakra made problems.

I’m not entirely sure what causes the problem - it is nearly impossible to figure out which package is the trouble maker but I think I have narrowed it down to your implementation of framer_motion.motion.custom() (v3^) or framer_motion.motion() (v4^ | v5^ | v6^). I’m not sure what webpack does here but I guess it injects a placeholder for framer-motion and since I only have framer-motion v6^ it does not know what to do.

I get the error:

TypeError: framer_motion__WEBPACK_IMPORTED_MODULE_9__.motion.custom is not a function. (In 'framer_motion__WEBPACK_IMPORTED_MODULE_9__.motion.custom(_chakra_ui_system__WEBPACK_IMPORTED_MODULE_8__.chakra.div)', 'framer_motion__WEBPACK_IMPORTED_MODULE_9__.motion.custom' is an instance of Object)

And going through my bundled source I could find the affected line:

var MenuTransition = true ? framer_motion__WEBPACK_IMPORTED_MODULE_9__.motion.custom(_chakra_ui_system__WEBPACK_IMPORTED_MODULE_8__.chakra.div) : (0,framer_motion__WEBPACK_IMPORTED_MODULE_9__.motion)(_chakra_ui_system__WEBPACK_IMPORTED_MODULE_8__.chakra.div);

However, downgrading to framer-motion v3.10.6 solves the issue but I doubt that this is a good workaround.

Can anyone help? Is this a webpack error?

Chakra UI Version

NEWEST

Browser

Safari

Operating System

  • macOS
  • Windows
  • Linux

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:21
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
lahlimcommented, Apr 5, 2022

Found a better workaround if downgrading is not possible! 💥 Issue comes from webpack 5.71.0

react-scripts installs the newest version of webpack so you can create a resolution to older version.

Add following resolution to package.json "resolutions": { "react-scripts/webpack": "5.70.0" },

Hope this will do until we get a proper fix! 🙃

2reactions
Poolsharkcommented, Apr 8, 2022

Hey! Thanks for the input! Unfortunately this does not really work for me, I have updated and now get the error:

ERROR in ../../../.yarn/__virtual__/framer-motion-virtual-db281f3046/0/cache/framer-motion-npm-6.2.9-a9d36266d7-3ba830affd.zip/node_modules/framer-motion/dist/es/utils/process.mjs 9:25-32

BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

Again it’s framer-motion, this is really frustrating!

UPDATE

I have managed to get it working! 🙌 I’m not really sure what I’m doing anymore - literally randomly trying out things to get stuff working… What has happened to the JavaScript world? Almost every package I had was updated and resulted in breaking changes - I need a new job 🙈

Solution (at least for me): Use Webpack’s ProvidePlugin to resolve the missing variable process. I personally use Craco so I had to add to craco.config.js:

const webpack = require("webpack");

module.exports = {
  ...
  webpack: {
    plugins: {
      add: [new webpack.ProvidePlugin({ process: "process/browser.js" })]
    }
  }  
}

Don’t forget to install process!

The key was to add .js to process/browser - guess this is the same if you use webpack only.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Webpack 5 Breaking Changes "process/browser"
I npm installed every dependency I could, but I'm still getting this error for "process/browser". I'm not really sure how to identify the ......
Read more >
Upgrade guides | Framer for Developers
In this guide we'll take a look at how you can upgrade your code to ensure it continues to work as expected, and...
Read more >
framer-motion | Yarn - Package Manager
Undocumented APIs should be considered internal and may change without warning. [8.0.2] 2022-12-23. Fixed. Fixing defaults for hardware-accelerated animations.
Read more >
resolve.fallback: { "zlib": false } - webpack - You.com
Looked to be a problem with a library I was using. Open side panel ... i tried to Polyfill modules in webpack 5...
Read more >
Guide to creating animations that spark joy with Framer Motion
I went from knowing almost nothing about animations and transitions, ... There are many types of transitions available in Framer Motion so I ......
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