Trucks were invented in 1890s. By 1900 the world's population was 1.6 billion, 5 times smaller than it is now.
But population numbers aren't the only thing that has changed since then.
A hundred some years ago FDA didn't exist. You could buy eggs, meat, etc. from your local farmers and butchers. Now, you need licenses and to comply with a whole bunch of different codes. Fewer people can comply with those, so the average distance things need to be shipped has increased.
There's, also, a lot more things nowadays that were never possible to produce locally (or even just close by) to begin with. Semiconductors, medications, even fine fabrics for clothing require fairly complex processes and logistics. You can't just plop a fab or a lab in every large-ish city - that is going to be even more of a nightmare to supply with resources necessary to keep it running, than shipping final product from somewhere else far away.
Trains are great and they're definitely underutilized in the modern world, but the thing they excel at is getting stuff from point A to point B (like a warehouse), not spreading it around across thousands of different destinations.
Building a light railway to each and every walmart, target, 7eleven, etc. it's just not practical in any way:
My city, for example, has a relatively extensive tram system. You can get around most of the city by it and there's quite a few stores that are right next to tracks, so, theoretically, something like that could be used to deliver goods within a city.
However, it's, both, way louder than cars and trucks (I used to live right next to a railway) and every time a tram or its powerline break, the entire line stops. You can't, exactly, drive around a broken tram when you're on rail.