The cold war started immidiately after the Russian revolution in 1917. Western powers shared a deep fear of communism. Stalin and his party was always more afraid of the western powers than all others. In their fear, they found it more logical to ally to Germany in 1939.
Also, the United States was countering communists in China from the mid 1930's, greatly supporting Chang Kai Sheks nationalist army.