One thing the EU does is prevent a "race to the bottom" with regards to foreign trade agreements and tariffs. For example, if Poland wants to trade with China, they cannot negotiate directly. They must go through the EU. This prevents China from playing EU countries against each other to get better and better trade deals.
The EU also has labor and human rights protections built into it, so factories that move from Germany to Romania see far less benefit than a factory moving from the US to Mexico.