PuruVJ / neodrag

One Draggable to rule them all 💍
https://neodrag.dev
MIT License
1.59k stars 48 forks source link

Error when running jest tests. #141

Closed renegarcia225 closed 6 months ago

renegarcia225 commented 9 months ago

When running a Jest test i'm getting the following error:

SyntaxError: Cannot use import statement outside a module

This is how i'm importing the library:

import { useDraggable, DragEventData, DragOptions } from '@neodrag/react';

Seems like useDraggable is implemented as an esm moduel which is not compatible with jest.

houtan-rocky commented 6 months ago

@renegarcia225 Hi, can you give a minimal reproducible example?

But generally, I think that's cause jest isn't compatible with esm module, And this isn't only related to Neodrag,

so consider going through the instructions from the jest documentation to be able to run Jest in esm: https://jestjs.io/docs/ecmascript-modules

You also can consider migrating to vitest as its API is 99% compliant with jest and supports esmodules.

PuruVJ commented 6 months ago

Agreed. We won't be shipping a CJS version, so I'd suggest figuring out a way to run ESM libs in Jest.