There is a way to prevent this from occurring and to change the cat’s perception of the carrier.
I prefer the top loading carriers personally and long before using it I recommend that people find a place where they are comfortable having the carrier permanently where it is always accessible to the cat. Then leave it open and put something very cushy and lush in there to encourage the cat to choose that as one of the places to snooze. I also recommend putting a special treat in the carrier, like freeze dried salmon, a couple of times a week for the life of the cat. We want to create a desire in the cat to spend time being comfortable in the carrier, as well as checking it out frequently for good stuff.
If you have a cat that just panics when you get the carrier the easiest way to remedy that is to re-home that carrier and get another one. If it was front loading get a top loading carrier. If it was hard plastic one, get a soft carrier. Make that a great place to nap. Remember that behavior modification is about changing perception.