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

Undeclared dependencies error under Yarn PnP #733

Closed
gabormagyar opened this issue Mar 20, 2023 · 11 comments · Fixed by #882
Closed

Undeclared dependencies error under Yarn PnP #733

gabormagyar opened this issue Mar 20, 2023 · 11 comments · Fixed by #882

Comments

@gabormagyar
Copy link

Describe the bug

Yarn PnP needs all dependencies to be declared. This causes an error at runtime when the parser tries to access the following dependencies that are not declared in the manifest.

Example:

Error: @asyncapi/parser tried to access @stoplight/types, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

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

packageExtensions:
  "@asyncapi/parser@*":
    dependencies:
      "@stoplight/types": "^13.9.1"
      "@stoplight/json": "^3.20.2"
      "@stoplight/spectral-ref-resolver": "^1.0.3"
      "@stoplight/json-ref-readers": "^1.2.2"

The solution is to add these as dependencies or peerDependencies (optional or otherwise).

How to Reproduce

Install and run the parser under Yarn PnP package manager

Full errors with call stack:

@stoplight/types
Error: @asyncapi/parser tried to access @stoplight/types, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @stoplight/types
Required by: @asyncapi/parser@npm:2.0.0-next-major.15 (via /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/)

Require stack:
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/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/processors/AsyncAPIInputProcessor.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/processors/InputProcessor.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/processors/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/AbstractGenerator.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:22559:13)
    at Function.require$$0.Module._load (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22413: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/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/index.js:18:17)
    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:22603: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:22443:14)

Offending line seems to be this one: https://github.com/asyncapi/parser-js/blob/next-major/src/index.ts#L1

@stoplight/json
Error: @asyncapi/parser tried to access @stoplight/json, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @stoplight/json
Required by: @asyncapi/parser@npm:2.0.0-next-major.15 (via /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/utils/)

Require stack:
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/utils/mergeTraits.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/utils/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/v2/functions/channelParameters.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/v2/ruleset.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/v2/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/index.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/spectral.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/validate.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/parse.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/parser.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/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/processors/AsyncAPIInputProcessor.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/processors/InputProcessor.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/processors/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/AbstractGenerator.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:22570:13)
    at Function.require$$0.Module._load (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22424: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/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/ruleset/utils/mergeTraits.js:4:16)
    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:22614: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:22454:14)

Offending line seems to be this one: https://github.com/asyncapi/parser-js/blob/next-major/src/ruleset/utils/mergeTraits.ts#L1

@stoplight/spectral-ref-resolver
Error: @asyncapi/parser tried to access @stoplight/spectral-ref-resolver, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @stoplight/spectral-ref-resolver
Required by: @asyncapi/parser@npm:2.0.0-next-major.15 (via /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/)

Require stack:
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/resolver.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/spectral.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/validate.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/parse.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/parser.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/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/processors/AsyncAPIInputProcessor.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/processors/InputProcessor.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/processors/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/AbstractGenerator.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:22572:13)
    at Function.require$$0.Module._load (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22426: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/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/resolver.js:13:33)
    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:22616: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:22456:14)

Offending line seems to be this one: https://github.com/asyncapi/parser-js/blob/next-major/src/resolver.ts#L1

@stoplight/json-ref-readers
Error: @asyncapi/parser tried to access @stoplight/json-ref-readers, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @stoplight/json-ref-readers
Required by: @asyncapi/parser@npm:2.0.0-next-major.15 (via /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/)

Require stack:
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/resolver.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/spectral.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/validate.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/parse.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/parser.js
- /Users/mg/WebstormProjects/mbh/asyncapi-generator/.yarn/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/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/processors/AsyncAPIInputProcessor.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/processors/InputProcessor.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/processors/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/AbstractGenerator.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:22574:13)
    at Function.require$$0.Module._load (/Users/mg/WebstormProjects/mbh/asyncapi-generator/.pnp.cjs:22428: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/cache/@asyncapi-parser-npm-2.0.0-next-major.15-54e6ea0b35-2502272baa.zip/node_modules/@asyncapi/parser/cjs/resolver.js:15:28)
    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:22618: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:22458:14)

Offending line seems to be this one: https://github.com/asyncapi/parser-js/blob/next-major/src/resolver.ts#L2

@gabormagyar gabormagyar added the bug Something isn't working label Mar 20, 2023
@github-actions
Copy link

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@derberg
Copy link
Member

derberg commented Mar 30, 2023

@magicmatatjahu @smoya can you have a look? it makes sense to me.

we should not do things like import { DiagnosticSeverity } from '@stoplight/types' if dependency is not in package.json` but yeah, I do not know what are all the things you do there in 2.x 😄

actually I'm surprised how this got pass through linter 🤔 for me npm run lint throws like 58165 issues 😆 but I guess I broke something

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale label Jul 29, 2023
@woylie
Copy link
Contributor

woylie commented Oct 16, 2023

I don't have any additional details, but this is definitely still an issue.

Copy link
Member

derberg commented Oct 16, 2023

ping @magicmatatjahu @smoya - can you have a look?

@smoya
Copy link
Member

smoya commented Oct 16, 2023

I couldn't reproduce the issue. I used the following code:

import { Parser, Diagnostic, fromFile, DiagnosticSeverity } from '@asyncapi/parser';

const parser = new Parser();
function prettyPrint(diagnostics: Diagnostic[]) {
    for (const diagnostic of diagnostics) {
      if (diagnostic.severity === DiagnosticSeverity.Error) {
        console.log(diagnostic.severity, 'ERR', diagnostic.message);
      } else {
        console.log(diagnostic.severity, diagnostic.message);
      }
    }
}

const parse = async () => {
    const { document, diagnostics } = await fromFile(parser, './asyncapi.yaml').parse();
    prettyPrint(diagnostics);
    console.log("Done");
};

parse();

yarn.lock has the stoplight/types in it 🤔 .
However, I agree any dependency the parser directly relies on, should be in the package.json 👍

Anyway, @gabormagyar Is there anything I need to do to reproduce the issue? Maybe you can share a snippet of code reproducing the issue? 🙏

@woylie
Copy link
Contributor

woylie commented Oct 16, 2023

Anyway, Is there anything I need to do to reproduce the issue?

You can try something like this:

mkdir asynctest
cd asynctest
yarn init -2
echo "nodeLinker: pnp" >> .yarnrc.yml
yarn add @asyncapi/generator @asyncapi/html-template

Then add this to package.json:

{
  "scripts": {
    "asyncapi": "ag asyncapi.yml @asyncapi/html-template"
  }
}

And finally, run:

yarn asyncapi

That returns:

/Users/me/asynctest/.pnp.cjs:18059
      Error.captureStackTrace(firstError);
            ^

Error: @asyncapi/parser tried to access @stoplight/types, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @stoplight/types
Required by: @asyncapi/parser@npm:2.1.0 (via /Users/me/asynctest/.yarn/cache/@asyncapi-parser-npm-2.1.0-7f076f680b-ed29f26851.zip/node_modules/@asyncapi/parser/cjs/)

Require stack:
- /Users/me/asynctest/.yarn/cache/@asyncapi-parser-npm-2.1.0-7f076f680b-ed29f26851.zip/node_modules/@asyncapi/parser/cjs/index.js
- /Users/me/asynctest/.yarn/cache/@asyncapi-generator-npm-1.14.0-d18a56be3f-2df02b19fb.zip/node_modules/@asyncapi/generator/cli.js
    at require$$0.Module._resolveFilename (/Users/me/asynctest/.pnp.cjs:18059:13)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at require$$0.Module._load (/Users/me/asynctest/.pnp.cjs:17948:31)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at Object.<anonymous> (/Users/me/asynctest/.yarn/cache/@asyncapi-parser-npm-2.1.0-7f076f680b-ed29f26851.zip/node_modules/@asyncapi/parser/cjs/index.js:18:17)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at require$$0.Module._extensions..js (/Users/me/asynctest/.pnp.cjs:18103:33)
    at Module.load (node:internal/modules/cjs/loader:1119:32)

After adding the packageExtension lines from the first post, it works (or at least, the error above disappears; there's a separate issue in html-template 1.0.0 at the moment).

@asyncapi-bot
Copy link
Contributor

Hello, @woylie! 👋🏼

I'm 🧞🧞🧞 Genie 🧞🧞🧞 from the magic lamp. Looks like somebody needs a hand!

At the moment the following comments are supported in issues:

  • /good-first-issue {js | ts | java | go | docs | design | ci-cd} or /gfi {js | ts | java | go | docs | design | ci-cd} - label an issue as a good first issue.
    example: /gfi js or /good-first-issue ci-cd

@smoya
Copy link
Member

smoya commented Oct 16, 2023

@woylie thanks for sharing! I could finally reproduce it. The important piece was to set the linker to pnp (as in your example) 👍 .
Additionally, yarn website mentions the issue we are facing as a good feature in pnp: https://yarnpkg.com/features/pnp#ghost-dependencies-protection

@woylie @gabormagyar any of you happy to create a PR with the fix?

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 2.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 3.0.0-next-major-spec.16 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants