This is true, but it's also a little misleading. The U.S. wasn't built by illegal aliens simply because this country hardly had any immigration laws at all until the 1920s -- after the lower 48 states had all been admitted into the Union.
If there were no immigration laws then there were no illegals here at that time.
True, the Chinese were instrumental in building the railways in the 19th century, and were notoriously good miners. I think the difference is most were just visiting Gold Mountain and were planning to return to China. Of course many didn't, but most did and many were killed when they refused to return after anti chinese legislation was passed. In St Helena a whole Chinese village south of town was massacred.
Almost every state as it was added to the union had their own policy for immigration before the feds developed a policy for all of us in 1924.