apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
351 stars 25 forks source link

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

Open kcy1860 opened 1 month ago

kcy1860 commented 1 month ago

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

phryneas commented 1 month ago

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.

elmaedesistemas commented 1 month ago

hi, news about this?

phryneas commented 1 month ago

@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).