In a lot of ways, fear is the primary motivator behind the Chinese Exclusion Act. Not just the fear you might be thinking of: spiders. (Because who's not scared of spiders?)
But not even xenophobia comes from an exclusively racist place.
Remember that the Chinese Exclusion Act partially came out of the Panic of 1873. "Panic" is a specific kind of fear. It's not the controlled kind that heroes get where they're running from dinosaurs. That kind of fear is rational. They can do stuff that makes sense, like shooting the dinosaurs, locking doors behind them, and regretting cloning dinosaurs in the first place. Panic means flailing and screaming.
You're doing dumb stuff, like excluding the Chinese from the country.
The Chinese Exclusion Act was born from the fear of economic collapse, and though it was targeted at a specific ethnicity, this was a political reality, as business interests were not going to be regulated.
The Chinese Exclusion Act was born from a fear of a very different culture and ethnicity. Though it used economics as a flimsy justification, it is fundamentally about race.
Despite the name, the Chinese Exclusion Act isn't entirely about race. There's a lot going on here, from an economic, political, and even practical standpoint. It's a complex issue, motivated by many all-too-understandable human foibles.
But come on, it's the Chinese Exclusion Act. It's not all about race, but you'd have to have both eyes closed and be humming at top volume to think race had nothing to do with it. The Chinese were a source of cheap labor, and they came from a very different culture than was prevalent in the United States at the time.
In this modern era, we know people of Chinese descent as our neighbors, our family, and our friends. The people in 1882 didn't know them like that yet.
The Chinese Exclusion Act used race as a smokescreen to hide its true economic agenda, of keeping wages at an artificially high level.
The Chinese Exclusion Act was a racist law that hid behind economics as a way to persecute a specific population of immigrants.
The people who wrote the Chinese Exclusion Act didn't get to know any Chinese people. They were judging the entirety of an entire ethnic group without meeting them.
Prejudice and racism are closely related, but they're not 100% the same thing. They often manifest identically, so it doesn't make a whole lot of difference. Racism is a dislike of a certain "race" (as defined by the person doing the disliking), and usually carries with it the idea that the racist is in the powerful majority ethnic group and the disliked party is a smaller group. Prejudice can be about anything. (It's usually race, though.)
The Chinese Exclusion Act used prejudice against the Chinese as a convenient lever to enact necessary legislation to protect jobs.
Prejudice of this kind can only find a home in ignorance, and diversity is the best way to combat such ignorance.
Any situation involving racism or prejudice is probably going to have shades of the struggle between majority and minority. Generally, the majority wants to protect what they have, while the minority would like a piece of the pie, please and thank you.
With the Chinese Exclusion Act, the majority were the white workers, while the minority was the Chinese immigrant labor force.
Though the Chinese immigrants ended up the scapegoats of the white labor force, it was a masterful ploy by the moneyed interests to distract hostility from them.
Though by today's standards the Chinese Exclusion Act is unconscionably racist, it did address a reality of the economics of labor by removing a significant minority in the labor force.
Before the 20th century, most of the immigrants coming to America were Europeans. Most of those were western European Protestants, too. So not just white people, but a very specific kind of white people. As the country got a significant population of Catholics, there was a lot of friction. The United States didn't have a Catholic president until 1960, and even then, his religion was brought up in the opposition campaign as a negative.
Most Chinese laborers were way more different that what Americans were used to. They were generally not Christians. They spoke a language totally different and alien-sounding to American ears. They didn't look like white people, or Native Americans, African-Americans, or Latinos. They were, in short, the dreaded Other.*
*The above has been an attempted deep dive into the minds of 19th-century narrow-minded people.
China's being seen as an extremely foreign country by the standards of 19th Century America made its immigrants vulnerable to this kind of legislation.
The Chinese Exclusion Act created a foreign population in the borders of the United States, and helped keep the Chinese-American population as the "other" within their own country.