I don't think that it is possible for the USA and Japan to be allied by the 1940s without changing world history to a degree that it becomes unrecognizable. American racism was built into the American character right from the beginning, it was simply part of the cultural landscape at the time that the Americas were colonized by Europeans, and the conflicts with the native Americans during the colonization served only to reinforce that. The nature of the colonization was such that capitalism became enshrined in the national character, and along with that and the relatively primitive nature of African civilisations - plus the propensity of some African tribes to sell the captured members of other tribes into slavery - and the technological inferiority of the Asian nations that served only to reinforce that.
On the Japanese side of the equation, the asian colonists who were the ancestors of the modern Japanese also had their own conflicts with the pre-existing native Ainu population, and later, they were involved in a failed invasion of the Korean peninsula, and they successfully fought off an invasion by the Mongols.
The Japanese have also had a long history of internal warfare, and a tradition of strong central authorities with a highly bureaucratic style of government. Militarism and a class-based society had become enshrined in the national character, with the ruling class also being the primary military class.
In Europe, the ruling military class held the concept of chivalry to be the highest military virtue. Most importantly, Chivalry enshrines the concept of respect of weakness, which translates to the modern western concept that once an enemy's surrender has been accepted, that enemy must be treated with a degree of respect, that while they may continue to be an enemy and may be imprisoned for the duration of hostilities, they must be provided with the basic necessities of life, and may even be paroled to return to return to their home provided that they swear an oath not to participate in any further hostilities in the conflict in which they were captured, tho the practice of parole has fallen into disuse in more recent times.
The Japanese had a similar code of military conduct, Bushido. While similar to Chivalry in many respects, it lacks a concept of respect of weakness, and contains a concept of courage in the face of any danger, and is entirely more fatalistic. In the Japanese outlook, surrender is dishonorable, a failure to fulfil a duty that may only be fulfilled by victory or death. So, to the Japanese, those who have surrendered have by their own actions marked themselves as being dishonorable, the lowest of the low, and not deserving of honorable treatment. Bushido makes no distinction between combatants and non-combatants, in war, all fight for their side of the conflict, even if not part of an army, and should engaging in combat be futile, then the only honorable options are escape in order to regroup and fight another day, or death, by one's own hand if necessary.
While Bushido didn't explicitly include the concept of suicide attacks that guaranteed the death of the warrior in return for a disproportionate number of enemy casualties, its fundamental tenets allowed the easy addition of suicide attacks.
With these fundamental differences between the respective nations concept of military honour, it is inevitable that the military personnel of each nation would be reluctant to work with those of the other nation, on the grounds of cowardice or cruelty. Only if the Americans and the Japanese were generally unaware of the requirements of each other's military honour code could an alliance reasonably be made, and I doubt that it would long survive the outbreak of hostilities against a common foe.
For many years, Japan practised a policy of isolationism, seeing those from outside their islands as being inferior and uncivilized. For many years, the main contact the Japanese had with Western nations was through missionaries attempting to spread Christianity. Unlike other peoples to whom missionaries have been sent, the Japanese recognised the presence of the missionaries as an attack upon their culture, and the message preached by the missionaries being antithetical to the interests of Japan's rulers. This led to an absolute ban on contact with the outside world, with only a few strictly controlled exceptions.
Japanese isolationism was only broken when the US sent warships commanded by Admiral Perry to force open the Japanese market. The Japanese, realizing that their isolationism had led to their falling behind the rest of the world, began an aggressive policy of modernization which led naturally to Japanese imperialism.
The fact that Japan's rapidly increasing technological base and population were at odds with the limited natural resources of the Japanese islands gave the Japanese an imperative to gain access to more resources, and given historical enmities, and the the nations who were the major source of the resources the Japanese needed refusing to trade made conflict inevitable.
So, given that the cultural differences that made conflict in WWII likely go back a thousand years, it would take a major event similar to Japan's defeat in World War II to change the Japanese national character sufficiently that an alliance would be possible... and if such an event had happened, one or perhaps both nations would no longer be the Japan or USA that we recognize, but another nations or nations that just happened to have the same name.