moleculer
moleculer copied to clipboard
Hot reload circular dependency in monorepos
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.
- Create monorepo
- Create project B
- Create project A that imports moleculer and project B
- Launch project A with hot reload
- 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);
}
Please create a repro repo.
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