47ng / nuqs

Type-safe search params state manager for React frameworks - Like useState, but stored in the URL query string.
https://nuqs.47ng.com
MIT License
4.86k stars 104 forks source link

Jest Test Suite Fails with "This package is ESM only" Error in Next.js v15 #737

Closed delinuxist closed 2 weeks ago

delinuxist commented 2 weeks ago

What's your version of nuqs?

"nuqs": "^2.1.1"

What framework are you using?

Which version of your framework are you using?

"next": "^15.0.2"

Description

When running Jest tests in my Next.js (v15) project, the test suite fails with an error indicating that the nuqs package is ESM only. This prevents me from successfully executing tests that involve components or hooks utilizing nuqs. Jest version "jest": "^29.7.0"

● Test suite failed to run

This package is ESM only.
  See https://github.com/47ng/nuqs/issues/691 for more details.

  13 | type QuoteAction = typeof createQuote | typeof updateQuote;
  14 |
> 15 | const useCreateQuote = () => {
       |               ^
  16 |   const queryClient = useQueryClient();
  17 |   const [quoteId, setQuoteId] = useQueryState('quote');
  18 |   const action: QuoteAction = quoteId ? updateQuote : createQuote;

  at Object.<anonymous> (node_modules/nuqs/esm-only.cjs:6:7)
  at Object.<anonymous> (hooks/use-create-quote.ts:15:15)
  at Object.<anonymous> (hooks/index.ts:37:64)
  at Object.<anonymous> (components/forms/policy-details-form.tsx:24:16)
  at Object.<anonymous> (__tests__/components/form/policy-details-form.spec.tsx:7:67)

Reproduction

franky47 commented 2 weeks ago

Check out #727 for solutions, and let me know how it goes.