apollo-link-logger icon indicating copy to clipboard operation
apollo-link-logger copied to clipboard

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

Open victorgarciaesgi opened this issue 5 years ago • 3 comments

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;

https://github.com/blackxored/apollo-link-logger/blob/73806916280054f6844ce1cc59b21f75b38ea542/src/index.js#L2

Possible fix comes from their docs

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

victorgarciaesgi avatar Nov 26 '20 22:11 victorgarciaesgi

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 avatar Apr 28 '21 13:04 chegger

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/[email protected]

chegger avatar Apr 28 '21 14:04 chegger

@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

victorgarciaesgi avatar Apr 30 '21 10:04 victorgarciaesgi

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

DavidMusijenko avatar Feb 21 '23 07:02 DavidMusijenko

:tada: This issue has been resolved in version 2.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Feb 22 '23 02:02 github-actions[bot]