Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Module not found: Error: Can't resolve 'react' in non-react environnements(Vue/Node) #60

Closed
victorgarciaesgi opened this issue Nov 26, 2020 · 5 comments · Fixed by #75
Closed
Labels

Comments

@victorgarciaesgi
Copy link

I have this error when compiling my Vue app with @apollo/client v3, and latest version from apollo-link-logger

The error comes from here, where you are importing from the entire @apollo/client package, and importing react;

import { ApolloLink } from '@apollo/client';

Possible fix comes from their docs

import { ApolloLink } from '@apollo/client/core';
@chegger
Copy link

chegger commented Apr 28, 2021

Having the same problem here. Although I've been using the apollo-link-logger and a similar apollo link (aws-appsync-auth-link) for a couple of months now, this is somehow breaking just now. In fact, when I look at the history of our ci/cd, it turns out that the apollo-link-logger was still working just ~10 hours ago.

I wonder why this is the case. @victorgarciaesgi's suggestion should do the trick, IMO. We are already using the @apollo/client/core module the exact same way in places of our codebase where react is not present.
This is also the suggested way of doing this according to this issue

@blackxored what do you think? I'd be happy to do an MR for this one, as I think it will make the package more compatible again!

@chegger
Copy link

chegger commented Apr 28, 2021

Also note, a clean and simple fix is actually just installing react via npm i react.

I was worried about using it as I thought react to be a large package, but a quick glance over to bundlephobia shows that it is just 7kB minified and 2.8kB minified + gzipped
https://bundlephobia.com/result?p=react@17.0.2

@victorgarciaesgi
Copy link
Author

@chegger The source code is rougthly ≃ 70 lines so I forked it and ported it into Typescript and put it locally on my projects to avoid putting react in dependencies

@DavidMusijenko
Copy link

I made a package with your solution if anyone needs it:
https://www.npmjs.com/package/apollo-link-logger-no-react

@github-actions
Copy link

🎉 This issue has been resolved in version 2.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants