@apollo/client v3 broken in Rollup & Snowpack
See original GitHub issueTracked 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:
- Created 3 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also about ES Modules related,
@apollo/client
still uses three dependencies exported as CommonJS:graphql-tag
(#6074)zen-observable
(#5961)fast-json-stable-stringify
I have noticed this trying to make
@apollo/client
work directly in the browser, without using any build/bundled process during development.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:
@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.@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.@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.