Skip to content
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

remove React as peer dependency #6532

Closed
finsec-dz opened this issue Jul 2, 2020 · 4 comments
Closed

remove React as peer dependency #6532

finsec-dz opened this issue Jul 2, 2020 · 4 comments

Comments

@finsec-dz
Copy link

Intended outcome:
Installing @apollo/client should not not display warnings of missing dependencies.

Actual outcome:

npm WARN @apollo/client@3.0.0-rc.10 requires a peer of react@^16.8.0 but none is installed. You must install peer dependencies yourself.

As per the migrating to v3 docs, @apollo/client can be used without React by importing from @apollo/client/core.

For projects NOT using React it should not be a required dependency.
I'm currently using it in an Angular project and the warnings should not be displayed.

How to reproduce the issue:

  1. Init a new project: npm init
  2. Install @apollo/client: npm i @apollo/client

Versions

@apollo/client@3.0.0-rc.10

@jonathonadams
Copy link

Any word from the Apollo team on this?

@Ksan8
Copy link

Ksan8 commented Nov 3, 2020

Related to this, I'm having trouble using useReactiveVar in Apollo Angular, as it gives missing React peer dependency warnings when imported from @apollo/client. If I try to import it from @apollo/client/core, as is recommended for other imports such as ApolloQueryResult, it cannot be found in that module (i.e., there is no such exported member).

Is it just not available for non-React projects?

// this results in compiler warnings about missing React dependencies
import { ApolloQueryResult, useReactiveVar } from '@apollo/client';

// this gets rid of the compiler warnings, but useReactiveVar cannot be found
import { ApolloQueryResult, useReactiveVar } from '@apollo/client/core';

Compiler warnings

ERROR in node_modules/@apollo/client/react/context/ApolloConsumer.d.ts:1:19 - error TS2307: Cannot find module 'react' or its corresponding type declarations.
    
    1 import React from 'react';
                        ~~~~~~~
    node_modules/@apollo/client/react/context/ApolloContext.d.ts:1:19 - error TS2307: Cannot find module 'react' or its corresponding type declarations.
    
    1 import React from 'react';
                        ~~~~~~~
    node_modules/@apollo/client/react/context/ApolloProvider.d.ts:1:19 - error TS2307: Cannot find module 'react' or its corresponding type declarations.
    
    1 import React from 'react';
                        ~~~~~~~
    node_modules/@apollo/client/react/types/types.d.ts:2:27 - error TS2307: Cannot find module 'react' or its corresponding type declarations.
    
    2 import { ReactNode } from 'react';
                                ~~~~~~~
    node_modules/@apollo/client/react/types/types.d.ts:145:63 - error TS2503: Cannot find namespace 'JSX'.
    
    145     children?: null | ((result: SubscriptionResult<TData>) => JSX.Element | null);

Versions

"@angular/[multiple packages]": "~10.2.0"
"@apollo/client": "^3.2.5",
"apollo-angular": "^2.0.4",

@hwillson
Copy link
Member

hwillson commented Jun 21, 2022

@Ksan8 useReactiveVar is a React Hook; it won't work without React. If you're interested in using reactive variables without React, see the Reactive variables section of our docs.

For the original issue here, until Apollo Client 4 is released (which will include a proper fix for this via #8190), we're going to investigate using peerDependenciesMeta and setting the React dependencies as optional. We'll explore this a bit and test things with alternate package managers (e.g. yarn, pnpm, etc.), and report back shortly.

@alessbell
Copy link
Member

alessbell commented Jun 22, 2022

@finsec-dz you should no longer see the peer dependency warning for react when installing @apollo/client@^3.0.0 with npm v7/v8, yarn v1/v2 or pnpm v6/v7 (and likely earlier versions, but docs only exist for the last two major versions of pnpm).

Given the date of this issue's creation, I'm wondering if you were using npm@v6 at the time which does not support peerDependenciesMeta in package.json which we use to identify the react peer dependency as optional.

Here are some screenshots of the terminal output of npm/yarn/pnpm install running node v16.15.0:

npm v8.10.0

No complaints
Screen Shot 2022-06-21 at 3 48 04 PM

yarn v1.22.19

Some warnings about react-scripts peer dependencies but nothing from @apollo/client
Screen Shot 2022-06-21 at 3 47 43 PM

pnpm v7.3.0

Note warnings for missing peer deps of two packages (react-app-rewired and stats-webpack-plugin) but not @apollo/client
Screen Shot 2022-06-21 at 3 56 03 PM

I'm going to close this issue for now, but please don't hesitate to re-open or create a new issue if you observe behavior that is not described above. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants