As the threat of blackouts continues to plague California, officials are pointing to battery storage as a key to preventing future power shortfalls. But the Golden State is going to need a lot more batteries to weather the next climate-driven crisis—let alone to achieve its goal of a carbon-free grid.

It won’t be cheap, potentially costing close to $19 billion. But more critically, there aren’t enough of these massive batteries to go around right now.

California’s latest energy crisis has several causes. For one, 9 gigawatts of gas generation—enough to power 6.8 million homes—was retired in recent years. Over that same period, the state’s grid integrated more solar power, which without sufficient battery storage can be less reliable than the fossil fuels that drive global warming.

In recent days, California’s worst heatwave in decades sent sweltering residents scrambling for their air conditioners. Typically, demand increases in the evening just as power from solar falls off. Batteries that store excess solar power can ease demands on the system at night, according to Adam Gentner, a vice president at German battery supplier Sonnen.

But there aren’t enough batteries installed on California’s grid right now. So power was curtailed Friday and Saturday, and may have to be cut again Wednesday.

California’s grid operator estimates that as much as 12 gigawatts of batteries would eventually be needed to store enough renewable energy to help maintain the balance between supply and demand. That’s a huge jump from the more than 500 megawatts worth of batteries operating in the state at the end of last year. At about $400 a kilowatt-hour and using 4-hour batteries, the entire effort could cost California close to $19 billion, according to Toby Shea, a senior credit officer at Moody’s Investors Service.

Meanwhile, only 4.6 gigawatts of energy storage is expected to be built in 2020—worldwide. The vast majority of that will come from batteries.

“If California wants to take renewable growth seriously, it has to commit to batteries, or something else,” Shea said in an interview.

California is already at the forefront of the clean-energy transition. Its ability to install enough storage to complement intermittent wind and solar power will be carefully watched as other regions follow suit. While Democratic presidential nominee Joe Biden is calling for carbon-free electricity by 2035, the state’s blackouts underscore that such a shift may be a bumpy one.

Read more: Energy Voice