React hook fails to compile
In a CRA running React 17 attempting to use the react hook import { useAutoAnimate } from '@formkit/auto-animate/react' results in the following error:
Failed to compile.
./node_modules/@formkit/auto-animate/react/index.mjs
Can't import the named export 'useEffect' from non EcmaScript module (only default export is available)
Not using the hook, and just using the autoAnimate function in a useEffect does however work
Good point — I think this is because React 17 isn't really ESM compliant.
Yes I had the exact same issue and couldn't use the hook. I just followed the basic example in the docs with useRef and it worked for me. Would be nice to be able to import the hook though.
Are both of these on React 17?
same issue with react 16 😅
Same issue react 18 😅😅
My Quick Fix: Instead of importing from ""@formkit\auto-animate\react", direct copy and paste it into your own codebase.
Im also having this issue
FWIW — I believe these issues are generally related to older bundlers that do not support native ESM imports and need a common js fallback. We don't currently ship a CJS bundle (and likely wont) since these older bundlers are quickly being replaced by ESM compatible build chains like Vite. If I'm wrong about this, and there's a way to get native ESM modules working by tweaking the export map, I think we'd be happy to get that merged in.
Hello,
I use on webpack this configuration and it's works !
config.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
});
:)