Javascript module imports takes too long

Viewed 123

I've created up a nodejs mono-repo project using tuborepo and the kitchen-sink template.

Here I have some applications, the code that I am going to release, and some packages, basically are shared functions and logic that the applications may or may not use.

It worked well, until some days ago, when I've found a strage behavior in some of my apps.

I have to make some changes to an application, so I've opened up Visual Studio Code, I've run yarn dev, and I was ready to code, but when I've started the application that need to update, I've noticed that it won't start, usually it takes some time, like 5 seconds at most, but this time it was taking up to 30-40 seconds util the node process exited.

I've tried with another application that is very similar but differs in some way, and I've encountered the same issue, so I've decided to create and empty test suite check if everything was still working fine, and it did, I mean the node process was not crashing and I've had the output I expected.

Then I've started to import from the packages the modules I needed, and I've noticed that a particular one causes this weird problem.

This module depends on other packages, and its main purpose is to serve up classes and functions that may be use from the application.

The problem is: when use the import ... from ... from the application code, the process hangs, then sometimes it can start properly so the code is executed, sometimes the node process exits, without an error message and with a status code of 0.

I've tried to use the process.on("uncaughtException") and process.on("unhandledException") but neither of them are ever fired, segault-handler doesn't help either since it does not report anything.

I've checked the code of this module, and it does not execute some functions or perform logic while it is importing, so I don't think it has to do with slow running functions.

I have only one theory, circular dependencies so a js file to includes another js file which itself includes the first one? but I don't think so since the code used to work just fine.

I've to use a backup of the code I have when It worked, but still, I do have the same error

I was wondering guys if you could please give me some hints to fix the bug, or if you had a similar issue explain how to solve.

0 Answers
Related