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

[Bug] moleculer does not find transporter for broker #2081

Closed
1 task
jeffrson opened this issue Nov 4, 2020 · 4 comments
Closed
1 task

[Bug] moleculer does not find transporter for broker #2081

jeffrson opened this issue Nov 4, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@jeffrson
Copy link

jeffrson commented Nov 4, 2020

  • I'd be willing to implement a fix

Describe the bug

moleculer (https://www.npmjs.com/package/moleculer) is a microservices framework that uses a "broker" to distribute commands and events and data. When a package depends on a library that includes moleculer and transporter, the transporter module is saved to the cache of the actual package but cannot be used from moleculer. It works with v1, though.

To Reproduce

The repro consists of multiple files. Therefore I created this repro repo: https://github.com/jeffrson/yarn2_moleculer

Instructions are given in the Readme. Essentially you should init yarn2, run yarn and start index.js via node from a package script.

Environment if relevant (please complete the following information):

  • OS: Windows
  • Node version 14.15.0
  • Yarn version 2.3.3

Additional context

It works with v1

This is most probably related to moleculer loading the module during runtime only when necessary:
https://github.com/moleculerjs/moleculer/blob/master/src/transporters/nats.js#L63

When moleculer and transporter are included in the app itself, ie not in a dependent library, there will be no such problem.

@jeffrson jeffrson added the bug Something isn't working label Nov 4, 2020
@andreialecu
Copy link
Contributor

andreialecu commented Nov 4, 2020

Without checking the repro itself, it seems that the line you linked from the moleculer source tries to require nats without defining it as a peerDependency in https://github.com/moleculerjs/moleculer/blob/master/package.json

This is a problem:
https://yarnpkg.com/advanced/rulebook/#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies

You can work around it by using packageExtensions:

packageExtensions:
  moleculer:
    peerDependencies:
      nats: "*"

Remember to rerun yarn install after updating your packageExtensions.

Here's an example on how this might be solved as a PR to moleculer: https://github.com/nestjs/nest/pull/5477/files

@Embraser01
Copy link
Member

An issue exists in the moleculer repo and a PR is open.

Issue: moleculerjs/moleculer#623
Pull Request: moleculerjs/moleculer#828

In the mean time the packageExtensions feature will work 🙂

@jeffrson
Copy link
Author

jeffrson commented Nov 4, 2020

Oh, well, I should have read the whole thread over there...

For the sake of correctness: packageExtension works, but needs something like "moleculer@*", instead of simply "moleculer".

@merceyz
Copy link
Member

merceyz commented Nov 4, 2020

I'll close this then since it has a fix upstream

@merceyz merceyz closed this as completed Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants