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

Yarn loader throws dependency error #415

Closed
zkulbeda opened this issue Jun 1, 2022 · 15 comments
Closed

Yarn loader throws dependency error #415

zkulbeda opened this issue Jun 1, 2022 · 15 comments

Comments

@zkulbeda
Copy link

zkulbeda commented Jun 1, 2022

When using esm imports and having "type":"module" in package.json

C:\Users\zkulb\WebstormProjects\ProjectX\.pnp.cjs:17509
      Error.captureStackTrace(firstError);
            ^

Error: @bull-board/api tried to access @bull-board/ui, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @bull-board/ui (via "@bull-board\ui\package.json")
Required by: @bull-board/api@npm:3.11.0 (via C:\Users\zkulb\WebstormProjects\ProjectX\.yarn\cache\@bull-board-api-npm-3.11.0-859450c715-0973ec382a.zip\node_modules\@bull-board\api\dist\src\)

Require stack:
- C:\Users\zkulb\WebstormProjects\ProjectX\.yarn\cache\@bull-board-api-npm-3.11.0-859450c715-0973ec382a.zip\node_modules\@bull-board\api\dist\src\index.js
    at require$$0.Module._resolveFilename (C:\Users\zkulb\WebstormProjects\ProjectX\.pnp.cjs:17509:13)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at eval (eval at createBullBoard (C:\Users\zkulb\WebstormProjects\ProjectX\.yarn\cache\@bull-board-api-npm-3.11.0-859450c715-0973ec382a.zip\node_modules\@bull-board\api\dist\src\index.js:13:47), <anonymous>:1:9)
    at createBullBoard (C:\Users\zkulb\WebstormProjects\ProjectX\.yarn\cache\@bull-board-api-npm-3.11.0-859450c715-0973ec382a.zip\node_modules\@bull-board\api\dist\src\index.js:13:47)
    at file:///C:/Users/zkulb/WebstormProjects/ProjectX/projectx-server/index.js:55:61
@felixmosh
Copy link
Owner

Hi, Thank you for reporting this issue,
Can you prepare a small repo that recreates the issue?

There is no import of @bull-board/ui from @bull-board/api.

@zkulbeda
Copy link
Author

zkulbeda commented Jun 1, 2022

Repo with issue
I suppose it happens when project uses workspaces.

@felixmosh
Copy link
Owner

Thank you, 🙏🏼
It solved in v3.11.1

@liogate
Copy link

liogate commented Jun 6, 2022

Hi 👋
I'm in v3.11.1 but still have the issue. Using yarn 2 with workspaces too.

Error: @bull-board/api tried to access @bull-board/ui, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @bull-board/ui (via \"@bull-board/ui/package.json\")
Required by: @bull-board/api@npm:3.11.1 (via /app/.yarn/cache/@bull-board-api-npm-3.11.1-d82eaa9769-2dddd9847c.zip/node_modules/@bull-board/api/dist/src/)

Require stack:
- /app/.yarn/cache/@bull-board-api-npm-3.11.1-d82eaa9769-2dddd9847c.zip/node_modules/@bull-board/api/dist/src/index.js
    at Function.require$$0.Module._resolveFilename (/app/.pnp.cjs:14367:13)
    at Function.resolve (node:internal/modules/cjs/helpers:98:19)
    at eval (eval at createBullBoard (/app/.yarn/cache/@bull-board-api-npm-3.11.1-d82eaa9769-2dddd9847c.zip/node_modules/@bull-board/api/dist/src/index.js:13:47), <anonymous>:1:9)
    at createBullBoard (/app/.yarn/cache/@bull-board-api-npm-3.11.1-d82eaa9769-2dddd9847c.zip/node_modules/@bull-board/api/dist/src/index.js:13:47)
    at default (file:///app/packages/core/plugins/bull.mjs:7:3)
    at Plugin.exec (/app/.yarn/cache/avvio-npm-7.2.5-99e44bde4a-9a0aa72084.zip/node_modules/avvio/plugin.js:132:19)
    at Boot.loadPlugin (/app/.yarn/cache/avvio-npm-7.2.5-99e44bde4a-9a0aa72084.zip/node_modules/avvio/plugin.js:274:10)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)","type":"Error","msg":"@bull-board/api tried to access @bull-board/ui, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @bull-board/ui (via \"@bull-board/ui/package.json\")
Required by: @bull-board/api@npm:3.11.1 (via /app/.yarn/cache/@bull-board-api-npm-3.11.1-d82eaa9769-2dddd9847c.zip/node_modules/@bull-board/api/dist/src/)

Require stack:
- /app/.yarn/cache/@bull-board-api-npm-3.11.1-d82eaa9769-2dddd9847c.zip/node_modules/@bull-board/api/dist/src/index.js

Thanks for you help !

@felixmosh
Copy link
Owner

Are you sure? Can you try older version?

@JasonMan34
Copy link
Contributor

@felixmosh I am getting this with @bull-board/api: "^4.11.0"

Error: @bull-board/api tried to access @bull-board/ui, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @bull-board/ui (via "@bull-board/ui/package.json")
Required by: @bull-board/api@npm:4.11.0 (via /app/.yarn/cache/@bull-board-api-npm-4.11.0-be42249947-17dc2cd3a4.zip/node_modules/@bull-board/api/dist/src/)

Require stack:
- /app/.yarn/cache/@bull-board-api-npm-4.11.0-be42249947-17dc2cd3a4.zip/node_modules/@bull-board/api/dist/src/index.js
- /app/.yarn/cache/@bull-board-express-npm-4.11.0-86649e135d-fce1d08007.zip/node_modules/@bull-board/express/dist/index.js
- /app/src/loaders/express.ts
- /app/src/index.ts

@felixmosh
Copy link
Owner

@JasonMan34 the API packages only resolves the path of @bull-board/ui with require.resolve("@bull-board/ui/package.json") nothing else.

@JasonMan34
Copy link
Contributor

JasonMan34 commented Apr 27, 2023

@felixmosh I understand that, but this still causes errors when using yarn. Yarn considers accessing the @bull-board/ui package without listing it as a dependency dangerous, so it fails to run (repro here)

Also, the error that yarn is referring to is a relevant and potentially dangerous one
Even if @bull-board/api only refers to @bull-board/ui in that one instance to resolve its package.json, this will cause the package to fail at runtime if not used in conjunction with @bull-board/ui. Repro here

I would make a PR that addresses this issue, but I am unsure of exactly what kind of dependency @bull-board/ui is to @bull-board/api (peer or normal dep)

@felixmosh
Copy link
Owner

@JasonMan34
I'm not able to reproduce your issue with the given repo
image

You should install @bull-board/express, it dependents on ui & api

@JasonMan34
Copy link
Contributor

JasonMan34 commented Apr 27, 2023

Interesting, yarn start worked for you out of the box in the reproduction repo? It should not by all means
What about with workspaces?

Either way, I don't understand why you wouldn't want to list @bull-board/ui as a dependency of @bull-board/api, when it is in fact a dependency of it. Even if ideally you would only want people using @bull-board/api with @bull-board/express, yarn won't let me do that because of the danger that the crash branch demonstrates

Error: @bull-board/api tried to access @bull-board/ui, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @bull-board/ui (via "@bull-board/ui/package.json")
Required by: @bull-board/api@npm:5.1.1 (via /Users/user/repos/bull-board-yarn-dep-bug/.yarn/cache/@bull-board-api-npm-5.1.1-533fa06b5d-b4570ef330.zip/node_modules/@bull-board/api/dist/src/)

@felixmosh
Copy link
Owner

felixmosh commented Apr 27, 2023

It will create a circular dependency, I've tested the crash branch, and I got the error.
Adding @bull-board/express solved the issue.

workspace branch works without issues
image

@JasonMan34
Copy link
Contributor

oh, I see from your screenshot now that your local code is using node_modules.
I am using yarn's zero-installs system, where the original error I mentioned happens (Even with @bull-board/express and everything, yarn refuses to resolve an ambiguous dependency)

Apologies for the misconfigured repro, I thought that using [email protected] would force pnp module resolution. I've added a nodeLinker: "pnp" setting to the repro, maybe it will happen to you locally now?

@felixmosh
Copy link
Owner

I will test asap

@felixmosh
Copy link
Owner

@JasonMan34 I'm able to reproduce the issue with pnp, if I'll define UI as a peerDeps of api, will it solve that issue?

Can you open a new issue that describes the issue with pnp?

@JasonMan34
Copy link
Contributor

Listing it as a peerDep should solve the issue
Opened an issue here

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

No branches or pull requests

4 participants