motion: [BUG] Can't import the named export 'Children' from non EcmaScript module (only default export is available)
1. Read the FAQs đ
2. Describe the bug ./node_modules/framer-motion/dist/es/components/AnimatePresence/index.mjs Canât import the named export âChildrenâ from non EcmaScript module (only default export is available)
Give a clear and concise description of what the bug is.
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
A CodeSandbox minimal reproduction will allow us to quickly follow the reproduction steps. Without one, this bug report wonât be accepted.
4. Steps to reproduce Run npm install framer-motion import { motion } from âframer-motionâ run npm start Steps to reproduce the behavior:
- Go to ââŚâ
- Click on ââŚâ
- Scroll down to ââŚâ
- See error
5. Expected behavior
A clear and concise description of what you expected to happen.
6. Video or screenshots
If applicable, add a video or screenshots to help explain the bug.
7. Environment details
If applicable, let us know which OS, browser, browser version etc youâre using.
FAQs
Type error with AnimateSharedLayout
AnimateSharedLayout was deprecated in 5.0. Refer to the upgrade guide for instructions on how to remove.
Preact isnât working
Framer Motion isnât compatible with Preact.
AnimatePresence isnât working
Have all of its immediate children got a unique key prop that remains the same for that component every render?
// Bad: The index could be given to a different component if the order of items changes
<AnimatePresence>
{items.map((item, index) => <Component key={index} />)}
</AnimatePresence>
// Good: The item ID is unique to each component
<AnimatePresence>
{items.map((item, index) => <Component key={item.id} />)}
</AnimatePresence>
Is the AnimatePresence correctly outside of the controlling conditional? AnimatePresence must be rendered whenever you expect an exit animation to run - it canât do so if itâs unmounted!
// Bad: AnimatePresence is unmounted - exit animations won't run
{isVisible && (
<AnimatePresence>
<Component />
</AnimatePresence>
)}
// Good: Only the children are unmounted - exit animations will run
<AnimatePresence>
{isVisible && <Component />}
</AnimatePresence>
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 31
Commits related to this issue
- see https://github.com/framer/motion/issues/1525 — committed to DataBiosphere/duos-ui by rushtong 2 years ago
- see https://github.com/framer/motion/issues/1525 — committed to DataBiosphere/duos-ui by rushtong 2 years ago
Fixed this by changing import to " import {AnimatePresence, motion} from âframer-motion/dist/framer-motionâ; "
When I use
framer-motion/dist/framer-motionI get typescript errors âŚI initially had this issue and it was fixed using the solution provided in this thread using:
import {AnimatePresence} from âframer-motion/dist/framer-motionâ;
my app is a
create-react-appAnother solution that worked for me
I stumbled across another solution that worked for me, that doesnât require you to add /dist/framer-motion to the end of your import. This is when I updated
react-scriptsfrom4.0.0to5.0.1for improved compatibility with React 18.Refer to this changelog on how to update react-scripts https://github.com/facebook/create-react-app/blob/main/CHANGELOG.md
part of my package.json before:
part of my package.json after updating react-scripts:
After updating
react-scripts, I deletednode_modulesandpackage-lock.json. After that,npm ito install all dependencies again.I then got this error:
ERROR in ./src/Components/ComponentName/Component.jsx 11:0-89
Module not found: Error: Package path ./dist/framer-motion is not exported from package /Users/username/projectpath/projectname/node_modules/framer-motion (see exports field in /Users/username/projectpath/projectname/node_modules/framer-motion/package.json)
This is where I removed /dist/framer-motion from the end of the import, and it worked for me.
If you canât upgrade
react-scriptsto version 5, another workaround that worked for me is from this answer here:framer-motion-types.d.tsfile in your src directoryimport { AnimatePresence, motion } from "framer-motion/dist/framer-motion";https://github.com/framer/motion/issues/1525#issuecomment-1152007824 Please fix this i need typescript support.
This is a step-by-step guide to fix the error âCanât import the named export âChildrenâ from non EcmaScript module (only default export is available)â which should work for most users with latest framer-motion version.
Step 1: Update Dependencies The first step is to update the versions of the following dependencies in your package.json file:
Again make sure all the versions are the same.
Step 2: Delete node_modules and Lock File After updating the dependencies, delete the node_modules folder and the lock file. You can do this by running the following command in your terminal:
Step 3: Install Dependencies Now run the following command in your terminal to install all the dependencies again:
Step 4: Start Server To import framer-motion use:
After installing the dependencies, start your server and the error should be fixed.
This guide has been tested on a sandbox environment and should work for most users.
All you have to do is update your
packages.jsonfile and delete thenode_modulesfolder and thelockfile then runnpm installoryarn installto install all the dependencies again OR you can just delete only the files related toframer-motionand remove it from yourpackages.jsonfile then installframer-motionagain.~ I hope this helped (ă_ă)
Updating the react-scripts was the solution to this inner node_modules error. Thanks!
Thank you @fabdul88 , Changing the react scripts version solved the issue
I tried all above solutions, nothing is working for me, i am using it in next js project.
Still experiencing this issue. Any updates?
I was having this issue (and the typescript issue with using the dist file) in webpack v4, but upgrading webpack to v5 fixed everything.
Iâve tried a lot of things, but the only thing that has worked so far is my project downgrading to framer-motion ^4.1.13. My project was a created with Codesandboxâs React Template. I canât imagine downgrading is the optimal solution. Any thoughts on this?
The 2nd solution works for me. Thank you !