EDNA, Texas — Early on the morning of June 20, 2018, Joe Hermes got a call from an executive in Walmart’s corporate offices. The caller was breaking some bad news: After 36 years, Walmart was closing its Edna store.

Mr. Hermes, who had been mayor of the small Texas city for about as long as the Walmart had been open, asked the man if he was joking.

“It was like getting hit by a bomb,” he recalled.

Walmart was Edna’s engine — one of its largest employers, a big taxpayer, a 24-hour social hub in a community of about 5,700 people surrounded by rice fields, ranches and grassland. The store, according to many patrons and employees, seemed successful, which made its closing even more alarming. Maybe Walmart knew something about Edna, or its economy, that the residents did not.

Case studies and books have examined what happens to a community when a Walmart muscles in, how the retailer uses its enormous leverage to lower prices and undercut competitors. But less has been said about what happens when Walmart suddenly packs up and leaves.