Although this problem needs a solution, a union is not that solution. Unions are a relic of a bygone era. The core premise of a union is that employes are all the same and can be swapped in and out of work like parts in a machine (once they are trained). This leads to collective bargaining which takes back some of the power that big employers have. However it also removes individuality from the worker. If I am smarter, stronger, or more skilled than my coworkers, I want to be able to elevate myself based on my merits. A union interferes with that. You pay a union, and the union acts only in its own best interest, not in your individual best interest.
Modern skilled workers, especially in the IT and Engineering fields, are usually very specialized. This is not a good fit for a union. It would be ill advised to take a good thing and remove all motivation for creativity and the free flow of invigorating talent.
A better solution is to simply prevent large corporations from getting away with their bullshit. No "gentleman's agreements" to prevent poaching. Stop accepting lies regarding layoffs and market performance. Reward employers for using home-grown talent rather than rewarding them with tax loopholes for moving overseas.