IN SOME respects this is a bumper era for solar energy. Last year, for the first time, the world invested more in photovoltaic cells than in coal- and gas-fired power generation combined. This year, new solar installations in America are expected to more than double (see chart ). China, which now has more solar capacity than any other country, plans to triple it by the end of the decade.

Yet this week two of the rich world’s most prominent solar-power developers have been flirting with disaster. Cheered on by yield-hungry creditors and investors, they had expanded too quickly, reliant on heavy borrowing and financial engineering. Not for the first time, some energy firms fooled themselves into believing that newfangled technologies and funding mechanisms could let them defy laws of financial gravity.

On March 29th SunEdison, an American firm that calls itself the world’s largest renewable-energy development company, was described in a public filing as facing a “substantial risk” of bankruptcy. A day earlier, the Wall Street Journal reported the firm was under investigation by the Securities and Exchange Commission (SEC) over accounting disclosures. Its debt exceeds $11 billion, gathered in just a few heady years.

Across the Atlantic, Abengoa, a big Spanish renewable and engineering firm with €9.3 billion ($10.6 billion) of debt, narrowly avoided bankruptcy this week after three-quarters of its creditors granted it a temporary reprieve to allow for the approval of a debt-restructuring plan. After four months of pre-bankruptcy proceedings, the truce was a big relief.

Both firms were emblematic of the excitement over clean energy. They borrowed oodles to build large projects that delivered energy to utilities at increasingly attractive prices. They then sold the assets to publicly listed and tax-efficient offshoots, known as “yieldcos”, that funded themselves by issuing shares. Since 2014 the biggest such share sales in America were by SunEdison’s yieldcos, TerraForm Power and TerraForm Global, and by the eponymous Abengoa Yield. Each raised over $500m.

But they were blinded by their own success, says Greg Jones of CreditSights, a financial-research firm. A plunge in oil prices and higher risk premiums for energy firms made it harder for yieldcos to raise money, which violated their promise to shareholders not only to issue steady payouts but also to increase returns. “They assumed there would always be access to capital markets,” he says.

SunEdison has become particularly erratic. In the middle of last year its bosses said its shares were substantially undervalued at $32. They have since fallen below $1. Analysts say its combination of acquisitive hubris, operational failures, murky financials and shoddy corporate governance cast a shadow over the clean-tech industry, though many firms are far more prudently managed.

SunEdison’s problems began last summer with a $2.2 billion merger agreement with Vivint Solar, a developer of rooftop solar controlled by Blackstone, a private-equity group. It hoped to use TerraForm Power to buy Vivint assets, but other TerraForm investors objected that the yieldco was becoming a dumping ground for SunEdison’s expensive acquisitions. Vivint ended up scrapping the merger.

In the autumn analysts at CreditSights drew attention to murky debt disclosures, which further battered confidence in SunEdison. The company has twice since delayed filing an annual financial statement and admitted to “material weaknesses in its internal controls over financial reporting”. That may explain the SEC’s interest, which exacerbates the concern of creditors. “It’s like a gigantic layer cake of debt,” says Mr Jones.

SunEdison had also upset TerraForm shareholders by saying Brian Wuebbels, its embattled chief financial officer, would become chief executive of the yieldcos, further subordinating their boards to the parent company. On March 30th both yieldcos announced his resignation.

The uncertainty is affecting its business activities. Hawaiian Electric, a utility that agreed to buy power from SunEdison, is trying to cancel the contracts because of the seller’s failure to meet financing deadlines, amid fears the projects could be drawn into bankruptcy proceedings.

Like SunEdison, Abengoa can only blame itself for its troubles. Its debt-propelled growth took place under the auspices of the founding Benjumea family, which has strong political connections. Abengoa built €28 billion-worth of projects between 2009 and 2015, including big water-desalination plants. Between 2011 and 2015 its debt-to-earnings ratio ballooned.

Many thought it was too big to fail. But strains grew last summer in Brazil, where it was building power-transmission lines. Abengoa admitted in July it would have to spend more than planned on its Brazilian projects. After denying it needed to raise more from investors, management announced a €650 million capital increase. That dented confidence; the firm’s share price slumped and banks pulled credit lines. It asked for preliminary protection from creditors in November. Most of its big construction projects have fallen quiet.

Abengoa hopes to reinvent itself. Under the restructuring plan, creditors would see 70% of debt swapped into equity. Existing shareholders would be left with just 5% of equity. That is painful but better than going into liquidation. The new Abengoa would receive fresh funding and do more “turnkey” construction for others. It would still labour under €4.9 billion of debt, but could at least focus on the type of engineering it does best. SunEdison may not have even that luxury.