Closed GuilhermeMelow closed 3 weeks ago
Yeah, getting Jest to work well with ESM packages is a bit of a sport, even in 2024.
I managed to make it work locally using these steps (following the Jest ESM guide):
extensionsToTreatAsEsm: [".ts", ".tsx"],
transform: {},
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest"
(adapt accordingly for Windows with cross-env)Note: tested using Node.js 20.18.0 and 22.11.0 (LTS).
Edit: I managed to also make it work in CodeSandbox by doing those steps and switching "module" to "CommonJS" in tsconfig.json. For some reason that last step wasn't needed when testing locally.
Thanks for you help! It's worked in parts, now this is throwing errors about global jest definition like in the print:
That's a Jest-specific issue now, not much to do with nuqs. Glad it helped you going forward!
:tada: This issue has been resolved in version 2.1.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
When I try to run tests and in this there are imports from
'nuqs/adapters/testing'
or any'nuqs/*'
, jest display me the error message:This package is ESM only. See https://github.com/47ng/nuqs/issues/691 for more details.
. I already reviewed the issue, but didn't find anything that could help me resolve this problem.Reproduction
https://codesandbox.io/p/live/7e72a9a1-a6f7-4696-83eb-5503e24fe781 Access the link, type
pnpm test
and press enter on terminal.