apollo-client-nextjs icon indicating copy to clipboard operation
apollo-client-nextjs copied to clipboard

Error 'ERR_REQUIRE_ESM' with "@apollo/experimental-nextjs-app-support"

Open kcy1860 opened this issue 1 year ago • 3 comments

Hi Maintainers,

I'm running into ERR_REQUIRE_ESM error when using it in my Next.js api route to load data (unhandledRejection: Error [ERR_REQUIRE_ESM]: require() of ES Module).

The issue seemed to be tied with [superjson ^2.0.0](https://github.com/blitz-js/superjson/releases) where it introduced a new change to make it ESM only: image

=============================================

I have worked around the issue by manually setting superjson version to 1.13.3 but just thought I should raise it here that the version specification should probably not include ^2.0.0 until it loads the module in ESM format.

Thanks for your attention

kcy1860 avatar Mar 07 '24 20:03 kcy1860

Yeah, that's a bit of a weird issue, that irritatingly only shows up in specific bundler combinations used by Next.js (not for all kinds of builds).

We are planning to drop the SuperJSON dependency completely, as it adds way too much bundle size and bloats the transported data unneccessarily - you can subscribe to https://github.com/apollographql/apollo-client-nextjs/issues/209 to track that.

phryneas avatar Mar 08 '24 11:03 phryneas

hi, news about this?

elmaedesistemas avatar Mar 20 '24 05:03 elmaedesistemas

@elmaedesistemas We will handle that in about two releases (targeting 0.11, with 0.9 hopefully going out today or tomorrow).

That said, our package allows for usage with both superjson 1 and 2, and you can configure your package.json to explicitly use one of them over the other (npm: overrides, yarn: resolutions).

phryneas avatar Mar 20 '24 09:03 phryneas