#1317·moleculer

regression ? In middleware call(next) hook: 'this' is now undefined in v0.14.33+

Author: TstassinCreated Jan 23, 2025Updated Mar 4, 2025
  • I am trying to upgrade from 0.14.32 to 0.14.33+
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I'm reporting the issue to the correct repository

Current Behavior

In MoleculerJS version 0.14.33+, the call(next) middleware hook no longer has access to the this context. In previous versions (e.g., 0.14.32), this inside the call(next) hook referred to the broker instance, which was useful for accessing broker-level properties like nodeID or logging functionalities.

Upon investigation, it seems this regression may have been introduced by the changes in Pull Request #1270, which adjusted the context binding in certain hooks. While this change likely aimed to address other issues, it inadvertently broke access to this in the call(next) hook.

Expected Behavior

I can access broker using 'this' in a call(next) hook

Steps to Reproduce

Using this codesandbox : https://codesandbox.io/p/devbox/moleculer-sample-forked-p4hjmx

Switch between versions 0.14.32 and 0.14.33 in package.json, npm iand see that with 0.14.32 it logs myNodeand with 0.14.33 it logs undefined