After migrating my project to use Yarn 2 and PnP requiring Postgraphile fails. I've managed to replicate the bug on a minimum setup.
Uncaught:
Error: graphile-utils tried to access graphile-build-pg (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: graphile-build-pg (via "graphile-build-pg")
Required by: graphile-utils@virtual:b4c5999b9717b0ae1a7ac87dc1db0246cd8f7e1dcc4994142c1128cfd338ab5f0e2007151a293597266c35c20993c1ef4f68e817d9bad399170bec602168a564#npm:4.11.2 (via /Users/garcianavalon/deleteme/yarn2postgraphile/.yarn/$$virtual/graphile-utils-virtual-d09b9026bf/0/cache/graphile-utils-npm-4.11.2-8f5ec4fc95-d1e2b40727.zip/node_modules/graphile-utils/node8plus/)
Ancestor breaking the chain: postgraphile@npm:4.11.0
Require stack:
- /Users/garcianavalon/deleteme/yarn2postgraphile/.yarn/$$virtual/graphile-utils-virtual-d09b9026bf/0/cache/graphile-utils-npm-4.11.2-8f5ec4fc95-d1e2b40727.zip/node_modules/graphile-utils/node8plus/fieldHelpers.js
- /Users/garcianavalon/deleteme/yarn2postgraphile/.yarn/$$virtual/graphile-utils-virtual-d09b9026bf/0/cache/graphile-utils-npm-4.11.2-8f5ec4fc95-d1e2b40727.zip/node_modules/graphile-utils/node8plus/makeExtendSchemaPlugin.js
- /Users/garcianavalon/deleteme/yarn2postgraphile/.yarn/$$virtual/graphile-utils-virtual-d09b9026bf/0/cache/graphile-utils-npm-4.11.2-8f5ec4fc95-d1e2b40727.zip/node_modules/graphile-utils/node8plus/index.js
- /Users/garcianavalon/deleteme/yarn2postgraphile/.yarn/cache/postgraphile-npm-4.11.0-b4c5999b97-6b96be303f.zip/node_modules/postgraphile/build/index.js
- /Users/garcianavalon/deleteme/yarn2postgraphile/.yarn/cache/postgraphile-npm-4.11.0-b4c5999b97-6b96be303f.zip/node_modules/postgraphile/index.js
- <repl>
at internalTools_makeError (/Users/garcianavalon/deleteme/yarn2postgraphile/.pnp.js:6127:34)
at resolveToUnqualified (/Users/garcianavalon/deleteme/yarn2postgraphile/.pnp.js:7059:23)
at resolveRequest (/Users/garcianavalon/deleteme/yarn2postgraphile/.pnp.js:7184:29)
at Object.resolveRequest (/Users/garcianavalon/deleteme/yarn2postgraphile/.pnp.js:7262:26)
at Function.external_module_.Module._resolveFilename (/Users/garcianavalon/deleteme/yarn2postgraphile/.pnp.js:6360:34)
at Function.external_module_.Module._load (/Users/garcianavalon/deleteme/yarn2postgraphile/.pnp.js:6225:48)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
yarn init
yarn set version berry
yarn add postgraphile
yarn node
> require('postgraphile')
require works correctly
Error: graphile-utils tried to access graphile-build-pg (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
node --version
v12.18.2
"postgraphile": "^4.11.0"
Add the missing dependencies to package.json
Temporary fix: using packageExtensions
# .yarnrc.yml
packageExtensions:
"graphile-utils@*":
dependencies:
"graphile-build-pg": "^4.11.2"
"graphile-build-pg@*":
dependencies:
"graphql": "^15.5.0"
"pg": "^8.5.1"
I've managed to fix the issue using packageExtensions to add the missing dependencies
# .yarnrc.yml
packageExtensions:
"graphile-utils@*":
dependencies:
"graphile-build-pg": "^4.11.2"
"graphile-build-pg@*":
dependencies:
"graphql": "^15.5.0"
"pg": "^8.5.1"
The final fix would be to update the package.json of graphile-utils and graphile-build-pg to add the missing dependencies.
@benjie are you interested in a PR to fix these missing deps?
It's critical that users have exactly one of certain dependencies installed:
graphqlgraphile-buildgraphile-build-pgwhereas others it's acceptable to have duplicates of:
postgraphilegraphile-utilsMost package managers err on the side of installing duplicate modules, even yarn, so to combat this we need to _not_ list dependencies - we list them as "peerDependencies" instead. They're mostly only needed for TypeScript types rather than runtime code (this isn't strictly true, but is a good approximation). I'm not willing to break the node_modules of npm and yarn v1 users just to make yarn2 happy, especially when the workaround you've listed above is so simple.
This comes down to an oversight in the node_modules pattern - there's no way of marking a particular package as "singleton" such that only one version of it may be installed in node_modules (making it work how ruby or python modules work, but only for that specific module). If we could solve that issue then listing them as "dependencies" would be fine.
Relevant rant: https://twitter.com/Benjie/status/1063145720868454401
Fair enough! Thanks for the explanation
@garcianavalon Can you see if [email protected] solves your issue? I've added graphile-build and graphile-build-pg as explicit dependencies to postgraphile.
Sure, I'll take a look this afternoon
On Tue, Feb 16, 2021, 12:09 Benjie Gillam notifications@github.com wrote:
@garcianavalon https://github.com/garcianavalon Can you see if
[email protected] solves your issue? I've added graphile-build
and graphile-build-pg as explicit dependencies to postgraphile.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/graphile/postgraphile/issues/1440#issuecomment-779765931,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAK6Y3J6BKEOZHI2GCUGWXTS7JG6PANCNFSM4XRB7BFQ
.
@garcianavalon (gentle nudge)
haha thanks for the nudge @benjie . I ended up ditching PnP mode in our project because of unsolvable issues on the frontend side and I had to wrap the week with some kind of progress 😅
I've try using the alpha version and I get the following result
yarn init
yarn set version berry
yarn add [email protected]
yarn node
> require('postgraphile')
Uncaught:
Error: graphile-build tried to access graphql (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: graphql (via "graphql")
Required by: graphile-build@virtual:57cb3f53e0300ef16db974e9e355277db0f247b7a1a1b61eea96cae80adcc372902458b1f18bede8cbad19201895a0065ef36b8a7158c5bc781c9ffdbb4ea84d#npm:4.12.0-alpha.0 (via /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-virtual-3151956220/0/cache/graphile-build-npm-4.12.0-alpha.0-d74cc20c17-7a383d929a.zip/node_modules/graphile-build/node8plus/)
Ancestor breaking the chain: graphile-build-pg@virtual:a0498cf3a8da4593c47c2226c6f7647f39c5e9ab1b6fb2d6f2de9a7facbabe48f56ca08aba858b81f69f67ac005e362397e46c578b9ed1b2446016d84079fbef#npm:4.12.0-alpha.0
Require stack:
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-virtual-3151956220/0/cache/graphile-build-npm-4.12.0-alpha.0-d74cc20c17-7a383d929a.zip/node_modules/graphile-build/node8plus/makeNewBuild.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-virtual-3151956220/0/cache/graphile-build-npm-4.12.0-alpha.0-d74cc20c17-7a383d929a.zip/node_modules/graphile-build/node8plus/SchemaBuilder.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-virtual-3151956220/0/cache/graphile-build-npm-4.12.0-alpha.0-d74cc20c17-7a383d929a.zip/node_modules/graphile-build/node8plus/index.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-pg-virtual-57cb3f53e0/0/cache/graphile-build-pg-npm-4.12.0-alpha.0-585101db6c-5190c65493.zip/node_modules/graphile-build-pg/node8plus/PgLiveProvider.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-pg-virtual-57cb3f53e0/0/cache/graphile-build-pg-npm-4.12.0-alpha.0-585101db6c-5190c65493.zip/node_modules/graphile-build-pg/node8plus/plugins/PgBasicsPlugin.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/graphile-build-pg-virtual-57cb3f53e0/0/cache/graphile-build-pg-npm-4.12.0-alpha.0-585101db6c-5190c65493.zip/node_modules/graphile-build-pg/node8plus/index.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/$$virtual/postgraphile-core-virtual-ff332b7a97/0/cache/postgraphile-core-npm-4.12.0-alpha.0-ded9a3ace6-84c0bc150d.zip/node_modules/postgraphile-core/node8plus/index.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/cache/postgraphile-npm-4.12.0-alpha.0-a0498cf3a8-24937953ae.zip/node_modules/postgraphile/build/index.js
- /Users/garcianavalon/deleteme/isitfix/.yarn/cache/postgraphile-npm-4.12.0-alpha.0-a0498cf3a8-24937953ae.zip/node_modules/postgraphile/index.js
- <repl>
at internalTools_makeError (/Users/garcianavalon/deleteme/isitfix/.pnp.js:6107:34)
at resolveToUnqualified (/Users/garcianavalon/deleteme/isitfix/.pnp.js:7039:23)
at resolveRequest (/Users/garcianavalon/deleteme/isitfix/.pnp.js:7164:29)
at Object.resolveRequest (/Users/garcianavalon/deleteme/isitfix/.pnp.js:7242:26)
at Function.external_module_.Module._resolveFilename (/Users/garcianavalon/deleteme/isitfix/.pnp.js:6340:34)
at Function.external_module_.Module._load (/Users/garcianavalon/deleteme/isitfix/.pnp.js:6205:48)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
I don't know if this is easily solvable, but since the packageExtensions fixes it I wouldn't worry too much