In a 3:1 (Z-pulley) haul, the victim's rope is used for hauling directly. As you point out correctly, a surface rescue is impossible if you have knots in the rope, since the rope is under tension and you cannot untie the knots.
However, you can also drop a different strand of rope down to the victim and haul them out with that (it's then called a rescue strand). Since it's not under tension, it's possible to remove all knots from the rope before sending it down.
Some examples are a 2:1 (C-pulley or drop loop) haul or a 6:1 (C cross Z) haul, where in both cases you drop a bight of rope down to the victim. They attach the rope (with a pulley) to their harness, and then the rescuers haul.
You could also send down a single strand of rope down and do a 3:1.
In any case, for a surface rescue, you need some rope available on the surface. All climbers tied together on a glacier should have some additional rope to perform a rescue.
Do note that all these require the victim to be conscious and able to help. If this is not the case, a rescuer needs to rappel into the crevasse, potentially address any immediate life-threatening injuries, clip the rope to the victim, ascend back out, then haul. This gets quite complicated, but is part of the guides' exam.
The last option would be for the victim to self-rescue, passing their prussiks over each knot in the rope. Clipping into the knots is possible and makes life a little bit easier.