Pakistan is awash with a tidal wave of Chinese infrastructure projects.

The small town of Gwadar, for example, was a forgotten end of the earth, filled with dust-colored cinder-block houses that lined trash-strewn streets and ringed by cliffs, desert and the Arabian Sea. Yet this sleepy fishing town has erupted with development over the past few years. A Chinese delegation inaugurated its sparkling new container port in early April, as part of a deal by which China will build and have rights over the port.

China has agreed to spend an extraordinary $46 billion in investment throughout Pakistan, far more than the annual U.S. aid budget for the entire world. This is now Beijing’s biggest commitment to any one country. Pakistan is also the largest recipient of Chinese weapons, and Beijing increasingly relies on it to help contain militants in China’s western provinces.

Pakistan holds a unique position in Chinese diplomatic circles. The Chinese state media describes Pakistan as China’s only “all-weather strategic cooperation partner.” Though it is the largest beneficiary of Beijing’s investment, it is not a client state, as North Korea is. Rather, in a neighborhood where many countries either distrust China, feel beholden to it or both, Pakistan is the closest thing to a real ally and friend that Beijing possesses.

This means that China and Pakistan sometimes cooperate in ways that concern the United States and India. Washington and New Delhi worry that all this largesse will bring Pakistan firmly into China’s orbit. With subtle diplomacy, however, all four countries may be able to create a workable balance.

The Gwadar port is just one example of China’s “One Belt, One Road” initiative. This effort is by far the most spectacular example of Beijing’s strategic policy of combining aid, trade and foreign direct investment to build goodwill, expand its global political sway and secure the natural resources it needs to grow.

Declaring that the Chinese-Pakistani friendship is “sweeter than honey,” and “stronger than steel,” Beijing announced last year that it would finance a 1,800-mile-long superhighway and a high-speed railway from the Arabian Sea over the Himalayas to China’s Xinjiang province. In addition, it would fund an oil pipeline route to the inland Chinese city of Kashgar. This network of infrastructure, including the Gwadar port, would help Pakistan grow, while pushing back against the growing power of regional competitors like India.

Helping Pakistan so dramatically also fits into China’s overall economic strategy. With a deep-sea port in the Arabian Sea and a land route to remote western China, some of Beijing’s Middle Eastern oil could travel the short route through Pakistan, instead of 6,000 miles through the Malacca Straits to Shanghai. That’s the route more than 80 percent of China’s oil and natural resources now have to take.

The infrastructure projects allow China to invest its large, if dwindling, foreign currency reserves, and also buy goodwill with its neighbors. Chinese state-owned companies get additional work, and the many energy projects that are part of the deal offer strong financial returns.

The initiative even has the convenient side effect of annoying India, Pakistan’s archenemy and China’s potential strategic rival.

Chinese engineers have already begun digging tunnels and building bridges to improve safety along the legendary Karakoram highway, one of the highest paved roads on earth, which links Pakistan to China. In addition, China is Pakistan’s largest trading partner and allows Pakistan special trade preferences through a free-trade agreement signed in 2006, though the volume of trade with Pakistan remains a drop in the bucket for Beijing.

As another sign of the growing alliance, Pakistan and China are close partners militarily, and their cooperation has increased in recent years. Pakistan accounts for more than a third of Chinese weapons sales.

In just the past seven months, Pakistan and China have conducted joint military exercises in Pakistan, China and, for the first time, in the East China Sea. China also built six nuclear reactors in Pakistan over the past two decades and expects to help build at least two more. This is raising concerns with the Nuclear Suppliers Group, an institution that supervises the export of global civilian nuclear technology.

In the 1980s and 1990s, China helped develop Pakistan’s nuclear weapons program. Some intelligence suggests that Beijing even helped with Pakistan’s new frightening miniature “battlefield” nuclear weapons, and with its first weaponized drone.

Many in India and the United States are alarmed about what they see as a China-Pakistan axis. They worry that China’s largesse means that Western nations will have little leverage to shape Pakistan’s actions on militants or nuclear weapons, or in supporting peace in Afghanistan. Another concern is that China would protect Pakistan when, for example, it refuses to cooperate with India and the West on handing over dangerous militants

Washington should indeed monitor the China-Pakistan relationship closely, but the signs are not all bad.

There is still much the world can do to prevent South Asia from splitting into two hostile China-Pakistan and India-U.S. camps, which is in no one’s interest.

The West should cautiously welcome China’s lavish economic investment in Pakistan because more development helps stabilize the country, a positive result for everyone.

Although China considers Pakistan an ally and a convenient access route to western China, China has broader interests in the region that may cause it to moderate Pakistan’s more worrisome tendencies.

China trades more with India than with Pakistan and shares with it a long, sometimes contested border. So despite sometimes touchy relations, China cannot afford to really antagonize New Delhi.

More broadly, addressing Islamic militancy is a serious goal for Beijing because small groups of Uighur militants have launched violent attacks in China and at times allied with the Pakistani Taliban, Islamic State and others. This alliance means that China is likely prodding Pakistan to do more to crack down on militants there. It could also have a positive effect for Afghanistan, where China has become engaged in pushing for peace talks, and just announced a small security aid package.

The United States, India and others should keep in mind that — weak as it is — Pakistan is one of China’s only real partners. They should engage both Chinese and Pakistani officials on economic development in the region, as well as terrorism and Afghanistan’s future. They should make clear, again and again, that Washington wants good relations with all states in the area. As long as India and the United States have a seat at the table, all four may be able to work out a satisfactory balance.

In this complex dance, there are no simple solutions.