Upgrading to 3.0.1 gives the following: Invariant violation: Could not find "client" #3381
Comments
I have the same issue. I just got started with apollo testing. Using versions:
This is how I use the MockProvider
This is the error:
|
Downgrading to 3.0.0 did the trick for me as a temporary fix:
|
It looks like Apollo/react-testing is using an old version of Apollo/react-common. (0.1.0-beta) which instantiate its own Apollo context. |
In my case, I found that I had |
I had the same issue. After I upgraded |
Everything is at |
Same issue. Using only |
I'm seeing this as well, even after rolling back to |
Any resolution? |
I'm having the same issue without any testing. I have ensured that I am only using "@apollo/react-hooks", perhaps interestingly in my package.json "@apollo/react-hooks": "^3.0.0" whereas in node-modules both react-common & react-hooks are "version": "3.1.0", |
I'm having this issue as well, not only with tests. |
Are you definitely using hooks in every component that calls a mutation or query. Mine is now working, not exactly sure why but I think that there was a component which was still using a render prop somewhere in the tree. |
Is anyone here still encountering this issue, using the 3.1.0 versions of all packages? |
So my problem is that I have no data coming through. Not sure what I'm doing wrong. My test file: https://github.com/shadrech/state-management-react-apollo/blob/tests/app/src/components/WorkerList/index.test.jsx Both @apollo/react-hooks and @apollo/react-testing are at v3.1.1 |
Same here as what @shadrech comment (probably not related in this specific issue and we have to open a new one):
after upgrade into |
@hwillson I just updated all of mine to 3.1.0 and am no longer experiencing that issue. |
I update all |
@hwillson I'm using 3.1.1 on everything, for sure, and facing this issue. I tried downgrading to 3.0 and re-upgrading to 3.1.1 and that seemed to work once, but as soon as I restarted my project, got the same error again EDIT: Not seeing the issue anymore. Will update if it returns. |
Ive also tried downgrading and upgrading to "@apollo/react-hooks": "^3.1.1", Getting the error |
3.1.1, still the same issue |
Did you open new issue @elrumordelaluz? |
Hey @shadrech, thanks for asking and I'm sorry that I didn't post before what I found. In my specific case I found the problem comes from |
Nice. My edge case was importing graphql files. I used parcel bundler for my app, with it I could easily do |
Use instead of
works fine. Lib version: |
I had the same issue and upgrading to:
fixed the Invariant |
Facing weird issues with When I use the following versions, my tests (jest) break:
When I use the following version, my storybook starts breaking:
|
Library that I use has import { useApolloClient } from 'react-apollo'; It breaks on invariant. However, when I call it from my code it works fine. EDIT: export { ApolloProvider } from 'react-apollo'; To the library. Now I am using 2 ApolloProviders, which seems to make it work, but it's a very dodgy solution |
I get the same error in production code, not in tests. Trying to upgrade from ^2.5.1 to ^3.1.0. |
Yes, I also had stopped using react-apollo! I had to add it back to get things to work. I also found this error was very inconsistent. It worked for me in development on my mac, and it worked for me in production if I built on my mac, but if I ran it in CI, or in a docker container, or on a Linux machine it would throw the error. The way I have it set up now seems very backwards but everything is working until a proper fix is released. |
@SeanRoberts would you mind sharing more details into how you’ve managed to solve this issue. |
In App.tsx
In package.json
Edit: I have no idea why this works, I just know that it works for me! |
@SeanRoberts worked for me! |
After further investigation we were able to solve the problem by moving away from using Once all imports were updated the MockProvider from |
@nearbycoder @SeanRoberts @acrogenesis @fernandopasik @jgfidelis @brense I faced same issue in monorepo just installing @apollo/react-hooks in package (not root), and it magically works without importing from it (I import only from react-apollo) I think it's a problem with module resolution or lerna links |
@Whispers12 might also be that you need to delete your node_modules directory and do |
@brense no, unfortunately it doesn't work (I tried), I think a real problem in this, that Lerna symlinks packages wrong way, but it's hypothesis. I just wrote what suites to my case, cause every other solutions in issues don't fit at all |
For some reason, adding |
@Whispers12 indeed apparently an issue with |
Still the same issue goes here. I am only using hooks in my project with the version of 3.1.3 of @apollo/react-hooks. Any solutions with this only? |
I have a solution, that works for me in 100% cases. I use @apollo/react-hooks Copy source code from mockedProvider and change ApolloProvider from @apollo/react-common to import {ApolloProvider} from "@apollo/react-hooks" and reimplement MockedProvider by myself |
I encountered the same issue with Forcing both packages to the same exact version in
|
This error has to do with the switch to the new Context API introduced in React 16.3. In my case, i passed a component containing an Apollo The incompatible context API could also explain why the workaround proposed by #3381 (comment) works. @hwillson do you think it is feasible to add a compatiblity layer to the |
I just tried the following combination (both at 3.1.4) but this did not work.
Instead going with both at 3.1.3, as @tony-ho suggested, seems to work!
|
Any idea on when this might be fixed? |
Updating to
resolved this for me. |
Faced the same issue. For me it was resolved by adding an alias to webpack's config: '@apollo/react-hooks': path.resolve('node_modules/@apollo/react-hooks') Looks like the problem happens because of different instances of the library. |
Just want to chime in here and say that I fixed this by downgrading both of the following packages:
This really should be more apparent. I am using React Testing Library with Jest. Hope this helps someone! |
Regenerating the |
I had the same issue, but because i put |
I had this issue because of mixed use of |
Intended outcome:
All my tests pass when I upgrade to
react-apollo
3.0.1 and@apollo/react-testing
3.0.1.Actual outcome:
I get the following error:
Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options
How to reproduce the issue:
Not quite sure but here's how I have my tests setup:
Version
The text was updated successfully, but these errors were encountered: