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

@types/zen-observable missing in dependencies list #8688

Closed
onichandame opened this issue Aug 23, 2021 · 6 comments
Closed

@types/zen-observable missing in dependencies list #8688

onichandame opened this issue Aug 23, 2021 · 6 comments

Comments

@onichandame
Copy link

onichandame commented Aug 23, 2021

Problem

This lib is compiled to use @types/zen-observable as a shadow dependency. This won't be a problem in node_modules as @apollo/client -> zen-observable-ts -> @types/zen-observable.

But it throws when used with yarn v2 PnP where shadow dependency is strictly forbidden. An example output is:

../../.yarn/__virtual__/@apollo-client-virtual-65fb8a2b1f/0/cache/@apollo-client-npm-3.4.8-69b6059fd9-07e4f32545.zip/node_modules/@apollo/client/link/utils/fromError.d.ts:1:23 - error TS2688: Cannot find type definition file for 'zen-observable'.
/// <reference types="zen-observable" />

There are dozens of such errors. After a quick glance at the code, I found that the source code does not use the shadow dependency at all, it is solely a result of the ts compilation.

Workaround

yarn v2 provides a way to patch the deps of packages:

# .yarnrc.yml
packageExtensions:
  "@apollo/client@*":
    dependencies:
      "@types/zen-observable": "*"

Solution

As simply patching @apollo/client with a dependency eradicates the errors, the straight forward solution would be fixing the dependencies list.

I have found a relating issue #2405 . It was once fixed but now on master branch the dependencies are removed again.

@onichandame onichandame changed the title zen-observable missing in dependencies list @types/zen-observable missing in dependencies list Aug 23, 2021
@benjamn
Copy link
Member

benjamn commented Aug 23, 2021

@onichandame I would very much hope https://github.com/apollographql/zen-observable-ts (a package we control) can abstract away these concerns without help or oversight from Apollo Client.

From your perspective, is there anything zen-observable-ts could be doing to prevent tsc from generating these /// <reference types="zen-observable"/> lines when compiling packages (like @apollo/client) that merely depend on zen-observable-ts and don't know/care about zen-observable?

It would be shame to require any package using zen-observable-ts also to run npm i @types/zen-observable, especially since the zen-observable-ts package has @types/zen-observable in the dependencies section of its package.json, so @types/zen-observable is guaranteed to be installed (even in production) when zen-observable-ts is installed.

What more can zen-observable-ts do here?

@onichandame
Copy link
Author

I am not sure how and why the reference line is generated. will look into it after work.

@benjamn
Copy link
Member

benjamn commented Aug 24, 2021

I wonder if there's a way we could just remove @types/zen-observable from the picture, maybe by internalizing those types within zen-observable-ts. I'll keep looking into to it.

benjamn added a commit to apollographql/zen-observable-ts that referenced this issue Aug 24, 2021
This allows us to remove the `@types/zen-observable` package entirely,
which should help with apollographql/apollo-client#8688.
@benjamn
Copy link
Member

benjamn commented Aug 24, 2021

I think that idea might work! apollographql/zen-observable-ts#152

@benjamn
Copy link
Member

benjamn commented Aug 24, 2021

@onichandame Can you try with @apollo/client@3.5.0-beta.8 (just published)? When I install that version, I no longer see the comments

/// <reference types="zen-observable" />

so I'm hopeful your issue will be solved.

@onichandame
Copy link
Author

My project has switched from PnP to node modules for ESM support, so I cannot reproduce the error in the original project.

Having tested @apollo/client@3.5.0-beta.8 in a fresh new project with PnP enabled, it worked!
Thanks a lot for your quick action :P

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 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

2 participants