A few things we can say play into this.
In the history of the nation really only 1 other nation has truly had the ability to bring a large army to American Shores, and sustain it. That being Great Britain and the Royal Navy, and they did just that in 1812.
Consider that Japan and the IJN, a great navy by any size measure, could barely project onto a handful of tiny rocks in the Aleutians and then couldn't hold them when pressed.
The US early on was able to be the big kid of the 3 nations in North America, Mexico was broiled in revolution, interventions, and instability and lost its war with the US. While Canada enjoyed the backing of British Arms, there was little interest then in expansion of the border South once American independence was confirmed, save for negotiations as both populations moved West. There were few resources only to be found on one side of the border. And there were more lucrative portions of the Empire to fight in for the British.
And while not large, the early USN was able to so well for itself and was backed by liberal usage of privateers. Making a blockade or landing supply or an army an expensive prospect, potentially endangering the naval trade of any nation attempting it. While the founding of the new steel navy in the 1880's finally set the nation on the path to being a first rate navy, with a force capable of meeting and defeating invasion forces.