One solution to this practice could be to discourage poor/underdeveloped/developing countries by giving them more options. Poor countries can either go to WB/IMF, invite private companies, or go to China.
The problem with WB/IMF is they put a lot of clauses/conditions which are on most occasions hard to implement for countries with weaker economies/infrastructures. Also, they require a lot of lobbying to the donor countries. Another problem is countries that are criticizing Chinese loans, mostly offer investments by private companies. Those companies prefer risk-free environments. As a result, countries which are, say, wartorn or have poorer infrastructures can't get those investments. These are the reasons why Chinese loans became so popular.
Why don't the USA (and like-minded countries) invest around the world as China does rather than only criticizing China, so that poor countries can have more options?