question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@apollo/client v3 broken in Rollup & Snowpack

See original GitHub issue

Tracked it back to this item:

https://github.com/apollographql/apollo-client/blob/master/src/react/react.ts#L8

The require function doesn’t exist inside an ES Module (any file with import or export syntax), which is causing the package to fail in some bundlers.

Happy to help brainstorm ideas on how to solve if you’d like, but would strongly recommend against shipping 3.0 with broken support in any major bundlers.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
abdonrdcommented, May 29, 2020

Also about ES Modules related, @apollo/client still uses three dependencies exported as CommonJS:

I have noticed this trying to make @apollo/client work directly in the browser, without using any build/bundled process during development.

4reactions
FredKSchottcommented, May 29, 2020

Yup, 100% agreed and wish this was better supported in ESM. But even Webpack is limited by how much it can statically analyze. Bundlers can see that @apollo/client is importing & requiring React, but they can’t tell at build-time wether that runtime function that does it will or won’t ever be run, so a bundler will normally just bundle “react” into your app just to be safe.

Based on the above, I’m 99% sure that Webpack is bundling "react" into every application that uses @apollo/client v3 regardless of whether the that code path ever gets hit. I don’t think it’s actually buying you that much.

I’d recommend:

  1. Decide that @apollo/client is for React, and remove the layer of indirection / just import react directly. Webpack is already including React anyway, so this isn’t too different from the way it is behaving today, but you’d be able to support Rollup, Snowpack, etc, etc.
  2. Split out anything React-specific from @apollo/client into a new @apollo/react or @apollo/client-react. I’d actually recommend this regardless of this issue, since it would help you scale to @apollo/client-{FRAMEWORK} without much thrash, but that’s just my outsiders opinion.
  3. Move anything React-specific into a @apollo/client/react sub-path within the package, and have users import from there directly. Everyone who npm installs the package will still get react as a dependency, but if the user never imports @apollo/client/react in their project, bundlers should be smart enough to handle that.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating to Apollo Client 3.0 - Apollo GraphQL Docs
WARNING: Apollo Client 3.0 is a major-version release that includes breaking changes. If you are updating an existing application to use Apollo Client...
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client helps you handle these errors according to their type, enabling you to show appropriate information to the user when an error...
Read more >
Subscriptions - Apollo GraphQL Docs
To support this, the @apollo/client library provides a split function that lets you use one of two different Link s, according to the...
Read more >
Apollo Link overview - Apollo GraphQL Docs
The Apollo Link library helps you customize the flow of data between Apollo Client and your GraphQL server. You can define your client's...
Read more >
Authentication - Apollo GraphQL Docs
Apollo Client uses the ultra flexible Apollo Link that includes several options for ... 3. import { ApolloLink, concat, split } from "apollo-link";....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found