Berry: [Bug] moleculer does not find transporter for broker

Created on 4 Nov 2020  路  4Comments  路  Source: yarnpkg/berry

  • [ ] 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.

bug

Most helpful comment

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

All 4 comments

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

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

Issue: https://github.com/moleculerjs/moleculer/issues/623
Pull Request: https://github.com/moleculerjs/moleculer/pull/828

In the mean time the packageExtensions feature will work 馃檪

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".

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

larixer picture larixer  路  4Comments

dzintars picture dzintars  路  3Comments

milichev picture milichev  路  3Comments

joshmeads picture joshmeads  路  4Comments

IanVS picture IanVS  路  4Comments