motion: [BUG] Latest version incompatible with NextJS 15 build?
Hello everyone and thanks for such a nice library! đ
Anyway, my NextJS build is failing due to an error when using latest version 12.11.1:
Runing next build throws this error:
./node_modules/framer-motion/dist/es/index.mjs
Error: It's currently unsupported to use "export *" in a client boundary. Please use named exports instead.
at Object.transformSource (.../node_modules/next/dist/build/webpack/loaders/next-flight-loader/index.js:104:53)
Import trace for requested module:
./node_modules/framer-motion/dist/es/index.mjs
Any clue what could cause this?
My versions:
"next": "15.3.2",
"react": "19.1.0",
"react-dom": "19.1.0",
Package is at @12.11.1
Thanks
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 13
- Comments: 24
Commits related to this issue
- fix: lock motion version to v12.18.1, to avoid issue #3321 https://github.com/motiondivision/motion/issues/3211 — committed to react-zero-ui/core by Austin1serb a year ago
We encountered it today when upgrading from 12.15.0 to 12.19.1.
It appears all import from
motion/reacttrigger this error. We importMotionConfig,AnimatePresence.Versions that do not trigger the error for us:
Versions that do trigger the error for us:
I can reproduce this on the following CodeSandbox: https://codesandbox.io/p/devbox/2dsgl3 It is simply the default NextJS template with an added import in the
layout.tsxYou see the error in the build action.đ§ What changed
In ⤠12.18.1,
motion/reactexported all symbols explicitly from a"use client"file:â This worked in Next.js App Router with React Server Components.
In 12.18.2+, that file was replaced by a one-line wrapper:
â This causes Next.js builds to fail with:
Error: Itâs currently unsupported to use âexport *â in a client boundary. Please use named exports instead.
⸝
đ§ Why this breaks in Next.js
Next.js (via React Server Components + Flight compiler) requires statically analyzable named exports from âuse clientâ modules to build its proxy system.
export * makes the export surface dynamic, the compiler canât resolve whatâs being exported at build time, so it throws an error.
This is a known limitation of the current React Server Components architecture.
⸝
đ Other libraries with the same issue
This isnât a Motion-specific bug -> itâs a pattern others have hit too:
⸝
â Next step
@mattgperry if youâre open to it, Iâm happy to submit a PR that restores compatibility with Next.js App Router by ensuring only named exports are used in âuse clientâ files - without reverting the flattened path structure introduced in 12.18.2.
Let me know if that sounds like a good direction and Iâll get something started after the 4th of July.
Reverted way back to
^12.15.0but no joy! It seems the error is coming from a Sanity related library.I LOVE motion. honestly one of the greatest libs out there. but yes sadly, this is a major issue. as soon as I update past âmotionâ: â12.19.0â it stops working.
I am able to fix using the same work around @RobotoSkunk mentioned above. using a wrapper to import import { domAnimation, LazyMotion } from âmotion/reactâ, with the âuse clientâ directive.
is this a pattern we need to use going forward, or are you looking to make this still work with SSR?
Getting the same error with latest version
Reverting to 12.17.0 seems to fix it
Iâm seeing it via sanity as well:
I ran into the same issue, though it doesnât seem to have broken in 12.11. If I force both
motion-domandframer-motionto12.7.4it works fine, but it breaks if I install12.7.5. Iâm not depending directly onframer-motionmyself, but transitively throughsanity-packages.