How to detemine and handle cyclic dependencies that cause a function to not be found

Sometimes the code base I work with is very messy and sometimes I run into a problem where

Caused By: TypeError: <FUNCTION NAME HERE> is not a function

When in fact, it is a function that my IDE can even go to if i click on it or even if method is in same directory.

I learned sometime ago that sometimes if files / packages get a bit to hairy and im importing one module (file) and another and both are used and imported else where at same time, it can cause some cyclic dependency issue and the solution is to move out or extract out one of the functions or move around the files differently.

Now the error doesn’t say it is a cyclic dependency issue but i learned this by stack overflow and refactoring the files.

One issue is, this doesnt show up until run time and hard to detect so I am wondering if there is a better way to detect and handle these issues?

Thank you