-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Removing React from the default @apollo/client entry point #8190
Comments
> Note: I am expecting tests to fail for this commit, demonstrating the importance of using a stable serialization strategy for field arguments. Although fast-json-stable-stringify has done its job well, it only provides a "main" field in its package.json file, pointing to a CommonJS entry point, and does not appear to export any ECMAScript modules. Thanks to our conversion/abandonment of fast-json-stable-stringify and other CommonJS-only npm dependencies (zen-observable in #5961 and graphql-tag in #6074), it should now (after this PR is merged) be possible to load @apollo/client/core from an ESM-aware CDN like jsdelivr.net or jspm.io: <script type=module src="https://cdn.jsdelivr.net/npm/@apollo/client@beta/core/+esm"> </script> If you put that script tag in an HTML file, or inject it into the DOM of any webpage, you will currently see this error: Uncaught SyntaxError: The requested module '/npm/[email protected]/+esm' does not provide an export named 'default' This list of errors used to be longer, but now the only package left is fast-json-stable-stringify. Note that we're loading @apollo/client/core@beta here, not @apollo/client@beta. The reason @apollo/client itself is not yet ESM-ready is that react and react-dom are the two remaining CommonJS-only dependencies, and @apollo/client currently/regrettably re-exports utilities from @apollo/client/react. If importing from @apollo/client/core is a burden or feels weird to you, please know that we are planning to make @apollo/client synonymous with @apollo/client/core in Apollo Client 4.0, along with making @apollo/client/react synonymous with the v3 API of @apollo/client, though of course those will be major breaking changes: #8190
Fixing this issue should be treated as humanitarian work. |
FYI, for ESM it needs to be |
Fixed in #9940 🚀 |
This is insane but the problem was caused by the old apollo-client dependency which is 3 years old. The error was coming from ts-invariant code here https://github.com/apollographql/invariant-packages/blob/master/packages/ts-invariant/src/invariant.ts#L64 By this change I updated our app to use new @apollo/client dependency but there is one pretty big concern. This lib has react as a peer dependency (what?!) so to avoid adding react to our vue project I had to import needed functionality from @apollo/client/core instead of just @apollo/client. There is a discussion here apollographql/apollo-client#7318 According to this ^ apollo team are going to remove react from their peer dependecies list when apollo V4 will be launched. See apollographql/apollo-client#8190 That's another point why we should move away from using graphql entirely or at least stop using apollo. Issue: #5371 Change-Id: Ifd484efbcd9e99d8c2e21d0dab93670c9358e25c
This work was finished quite some time ago and we've changed quite a bit in the |
Apollo Client 3.0 streamlined our client codebases by merging React Apollo and Apollo Link directly into the Apollo Client core. As part of this stepping stone work, we wanted to ensure that React developers adopting Apollo were able to get up and running quickly. To this end, we made our React hooks available from the default
@apollo/client
entry point. People using Apollo Client that don't want to use React can use the@apollo/client/core
entry point instead, which ensures that our React code is tree-shakable.For Apollo Client 4.0 however, we would like to switch things around so
@apollo/client
by itself gives access to the Apollo Client core only, and importing from@apollo/client/react
will be required to get access to our React hooks. Doing this allows us to make certain assumptions about how people are using Apollo Client and optimize accordingly. It also opens up the possibility of leveraging other view layer integrations.This work will include:
@apollo/client
and@apollo/client/react
accordinglyThe text was updated successfully, but these errors were encountered: