sourcemeta/alterschema

Undeclared dependencies error under Yarn PnP

Closed this issue · 7 comments

Describe the bug

Yarn PnP needs all dependencies to be declared. This causes an error at runtime because of an undeclared dependency in the the outdated @hyperjump/json-schema@npm:0.23.2 package:

Error: @hyperjump/json-schema-core tried to access just-curry-it, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: just-curry-it
Required by: @hyperjump/json-schema-core@npm:0.28.5 (via /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/unplugged/@hyperjump-json-schema-core-npm-0.28.5-e8b590eb0d/node_modules/@hyperjump/json-schema-core/lib/)

Require stack:
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/unplugged/@hyperjump-json-schema-core-npm-0.28.5-e8b590eb0d/node_modules/@hyperjump/json-schema-core/lib/core.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/unplugged/@hyperjump-json-schema-core-npm-0.28.5-e8b590eb0d/node_modules/@hyperjump/json-schema-core/lib/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/unplugged/@hyperjump-json-schema-npm-0.23.2-60615ed1a8/node_modules/@hyperjump/json-schema/lib/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/alterschema-npm-1.1.2-0b4aecd6cc-4bdc5f89e4.zip/node_modules/alterschema/bindings/node/jsonschema.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/alterschema-npm-1.1.2-0b4aecd6cc-4bdc5f89e4.zip/node_modules/alterschema/bindings/node/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-modelina-npm-2.0.0-next.4-52848d6dc3-f26a0e0414.zip/node_modules/@asyncapi/modelina/lib/cjs/generators/typescript/presets/JsonBinPackPreset.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-modelina-npm-2.0.0-next.4-52848d6dc3-f26a0e0414.zip/node_modules/@asyncapi/modelina/lib/cjs/generators/typescript/presets/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-modelina-npm-2.0.0-next.4-52848d6dc3-f26a0e0414.zip/node_modules/@asyncapi/modelina/lib/cjs/generators/typescript/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-modelina-npm-2.0.0-next.4-52848d6dc3-f26a0e0414.zip/node_modules/@asyncapi/modelina/lib/cjs/generators/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-modelina-npm-2.0.0-next.4-52848d6dc3-f26a0e0414.zip/node_modules/@asyncapi/modelina/lib/cjs/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/build/src/generate.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/build/src/program.js
    at Function.require$$0.Module._resolveFilename (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22575:13)
    at Function.require$$0.Module._load (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22429:42)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/unplugged/@hyperjump-json-schema-core-npm-0.28.5-e8b590eb0d/node_modules/@hyperjump/json-schema-core/lib/core.js:1:15)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Object.require$$0.Module._extensions..js (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22619:33)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.require$$0.Module._load (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22459:14)

Again, that this isn't a problem with the alterchema package, but with an outdated dependency:

➜  yarn why @hyperjump/json-schema-core -R
...
      └─ alterschema@npm:1.1.2 (via npm:^1.1.2)
         └─ @hyperjump/json-schema@npm:0.23.2 (via npm:0.23.2)
            └─ @hyperjump/json-schema-core@npm:0.28.5 (via npm:^0.28.0)

Workaround

The workaround is to add the undeclared dependency to the user package's .yarnrc.yml file like so:

packageExtensions:
  "@hyperjump/json-schema-core@*":
    dependencies:
      "just-curry-it": "^5.3.0"
  "@hyperjump/json-schema@*":
    dependencies:
      "@hyperjump/pact": "^0.2.5"

Solution

The solution is to update the @hyperjump/json-schema package to a newer version where this issue is no longer present.

How to Reproduce

Install and run the package under Yarn PnP package manager

Hey @gabormagyar , thanks for the heads up. I'll try to get #117 merged today. There are some breaking changes in @hyperjump/json-schema that need to be resolved.

@jdesrosiers Is there a chance we could get a fix for this back ported to the previous versions of Hyperjump? While I'm using the v1 line on other projects, they do require ESM, which will be hard to include for this particular project without breaking a bunch of users still using require().

I could still use the ESM one, probably with a build step, but it will take me a while, and a back ported fix could unblock @gabormagyar

Thanks, it's very nice to see that this is gaining attention, but the workaround I described means that this isn't blocking me luckily. Feel free to get this fixed whenever convenient.

Thanks @gabormagyar !

I generally don't intend to maintain the 0.x version, but this is easy enough. I've published v0.23.5 that includes the missing dependency.

Thanks a lot @jdesrosiers 🙏🏻 Let me do an Alterschema release with this fix

I published 1.1.3 to npm.