There is no contradiction. Nationalism is about loving your compatriots, not about taking foreigners. In many situations, like in this pandemic, or with global climate change, if you really love your compatriots, and you want to take care of them, you have to cooperate with foreigners.