Describe the bug
Some packages still aren't able to resolve the warning even after fixing them with the packageExtension config in .yarnrc.yml
Error: apollo-utilities tried to access graphql (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
In my .yarnrc.yml I have the following:
packageExtensions:
"apollo-utilities@*":
dependencies:
"graphql": "^15.0.0"
To Reproduce
Checkout - https://github.com/jeffsee55/yarn-2-package-extension-issue
yarn installyarn generate - you should see the error aboveTo see it working without pnp:
yarn install yarn generate - you should see the graphql-codegen cli start in your terminal.I understand this is ultimately an issue with the package manager but would like to learn me about why this sometimes still doesn't work and how I might be able to dig into it deeper.
Environment if relevant (please complete the following information):
Additional context
Also - if this is in a monorepo it hurts worse because that means I need to undo all of my pnp setup for other packages. Is there any way to just disable pnp for a single package in a workspace?
I and a colleague have spent several hours on this issue over the past two days, getting increasingly frustrated. I don't think what you're seeing is a bug at all, I think the fix you're trying in packageExtensions just isn't correct.
run yarn. You'll get this message:
โค YN0000: โ Resolution step
โค YN0002: โ apollo-upload-client@npm:13.0.0 doesn't provide graphql@^0.11.3 || ^0.12.3 || ^0.13.0 || ^14.0.0 || ^15.0.0 requested by apollo-link@npm:1.2.14
โค YN0002: โ apollo-upload-client@npm:13.0.0 doesn't provide graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 requested by apollo-link-http-common@npm:0.2.16
โค YN0060: โ apollo-link@npm:1.2.14 [74d3c] provides graphql@npm:15.0.0 with version 15.0.0 which doesn't satisfy ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 requested by apollo-utilities@npm:1.3.3
โค YN0000: โ Completed
I can't reproduce your issue -- it seems to run fine. But I suspect if you fix the first warning there (ie give apollo-link@* a dependency on graphql) it should sort the issue.
The reason I say this is that what I've been fighting with today and yesterday is a React app built with Webpack. I install Apollo according to the Apollo React docs recommendation, try to build, and I get your error:
Error: apollo-utilities tried to access graphql (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
We tried all kinds of variations on your solution, except that needing to specify dependents for apollo-utilities wasn't the fix to the problem: we added apollo-client and apollo-utilities as standard dependents of @apollo/react-hooks, ran yarn, got a slightly different warning, added graphql as a dependency of apollo-link-error@* and everything just worked perfectly once that was done.
I think this is the solution here, I'm just going off me and my colleague fighting with Yarn for ages until we actually read the warnings it gives on install properly. Also, I assume loose mode would fix the issues as well, but I've literally only just seen it in the docs.
Package extensions are correct, they add the dependency to the right package. The problem is that for peer dependencies, there might be multiple problematic intermediaries. Take this:
. -> A -> B -> C -> D -peer-> X
-> X
Since C doesn't provide X, Yarn throws an error saying that D is trying to access a dependency it doesn't list. However, it falls short of telling you that the reason for that is that C doesn't provide it!
D tried to access X (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: X (via "X")
Required by: [email protected] (via /path/to/D/index.js)
Making it difficult to fix, since you need to use yarn why to understand who's dependending on D, and which one is omitting to list a peer dependency on X. Then once you figure it out, you need to start again because B doesn't list it either, so you get the same problem ๐
This will be fixed with https://github.com/yarnpkg/berry/pull/1362, which will cause Yarn to list the also broken peer dependency links when throwing the error:
D tried to access X (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: X (via "X")
Required by: [email protected] (via /path/to/D/index.js)
Ancestor breaking the chain: [email protected]
Thanks to both of you for the input, @arcanis that's helpful to know - I tried just about every combination I could think of but the complexity in your example explains why I wasn't going to get it right any time soon.
TIL - yarn why is what would have helped me solve this on my own. Thanks again!
EDIT: happy to close this
hmm... I guess I'm still not getting it right...
โค YN0000: [@bb/apollo-test-util]: ../../../../.yarn/cache/apollo-engine-reporting-protobuf-npm-0.5.2-15aa08f143-f49534868b.zip/node_modules/apollo-engine-reporting-protobuf/dist/protobuf.d.ts(1,23): error TS2307: Cannot find module 'long' or its corresponding type declarations.
> yarn why -R apollo-engine-reporting-protobuf
โโ @bb/apollo-test-util@workspace:app-lib/graph/packages/apollo-test-util
โ โโ apollo-server-types@npm:0.5.1 [98c53] (via npm:^0.5 [98c53])
โ โโ apollo-engine-reporting-protobuf@npm:0.5.2 (via npm:^0.5.2)
this is the latest thing I've tried...
/.yarnrc.yml
packageExtensions:
'@bb/apollo-test-util@*':
dependencies:
apollo-server-types@^0.5:
dependencies:
[email protected]:
dependencies:
long: '^4'
devDependencies:
'@types/long': '^4'
oh I figured it out, I guess in my first iteration I missed a carat so I tried the above
packageExtensions:
apollo-engine-reporting-protobuf@^0.5:
dependencies:
long: '^4'
'@types/long': '^4'
Most helpful comment
Package extensions are correct, they add the dependency to the right package. The problem is that for peer dependencies, there might be multiple problematic intermediaries. Take this:
Since C doesn't provide X, Yarn throws an error saying that D is trying to access a dependency it doesn't list. However, it falls short of telling you that the reason for that is that C doesn't provide it!
Making it difficult to fix, since you need to use
yarn whyto understand who's dependending on D, and which one is omitting to list a peer dependency on X. Then once you figure it out, you need to start again becauseBdoesn't list it either, so you get the same problem ๐This will be fixed with https://github.com/yarnpkg/berry/pull/1362, which will cause Yarn to list the also broken peer dependency links when throwing the error: