Search code examples
javascriptreactjsnext.jsframer-motion

framer motion crashes next js app with the following error: "SyntaxError: Named export 'useId' not found"


I get this error on my next js app and I don't even know why or where its coming from since the code that's throwing the error is not even written by me.

error - file:///Users/cheq/Desktop/cheqo/node_modules/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs:1
import { useContext, useId, useEffect } from 'react';
                     ^^^^^
SyntaxError: Named export 'useId' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react';
const { useContext, useId, useEffect } = pkg;

I get this error when I import anything from framer motion, here is my full code:

import React from 'react';
import { motion } from 'framer-motion';

function motionpage() {
  return (
    <>
      <div>motionpage</div>
      <motion.button whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.98 }}>
        Button
      </motion.button>
    </>
  );
}

export default motionpage;

How can I fix this?


Solution

  • useId is a new hook introduced in React 18. Upgrade your react version and try again.