moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Hot reload circular dependency in monorepos

Open ishfx opened this issue 1 year ago • 2 comments

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [x] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] I'm reporting the issue to the correct repository

Current Behavior

In a monorepo, with 2 projects: a moleculer project and a helper project. The moleculer project imports the helper project. When the hot reload middleware is enabled, any file changes in the moleculer project causes high cpu usage because the hot relaod is stuck in circular dependency.

Expected Behavior

No circular dependency and normal hot reload.

Failure Information

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Create monorepo
  2. Create project B
  3. Create project A that imports moleculer and project B
  4. Launch project A with hot reload
  5. Change a file in project A and save.

Reproduce code snippet

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Moleculer version: 0.14.29
  • NodeJS version: v16
  • Operating System: Linux

Solution

Add option to hot reload middleware to ignore build directory of other monorepo projects (dist, build, out, etc)

Here is the line : https://github.com/moleculerjs/moleculer/blob/v0.14.29/src/middlewares/hot-reload.js#L241

Example with hardcoded value :

if (fName.indexOf("node_modules") !== -1 || fName.indexOf("dist") !== -1) {
  if (cache.get(fName)) return;
  cache.set(fName, mod);
}

ishfx avatar Jun 13 '23 19:06 ishfx

Please create a repro repo.

icebob avatar Jul 11 '23 16:07 icebob

I have similar problem.

Time if ignore /dist disabled: ✔ ServiceBroker with 43 service(s) started successfully in 6s Time if ignore /dist enabled: ✔ ServiceBroker with 43 service(s) started successfully in 3s

We need option like that: https://webpack.js.org/configuration/watch/#watchoptionsignored

grinat avatar Aug 18 '23 12:08 grinat