There are many ways to defeat a phalanx, but they all fall into two categories.



The first category is simply "a better phalanx", which can take multiple forms. Some classical examples include making the phalanx larger, making it smaller, providing longer spears, or providing lots and lots of javelins to soften up the enemy before the clash.


The second category centers on exploiting the phalanx's great weakness - it is an inflexible formation with very limited tactical mobility. This also takes many, many forms. Alexander compensated by supplementing his phalanxes with extremely good cavalry - he'd pin down the enemy with his own phalanxes, then use his cavalry to outflank them. Other classical solutions were artillery bombardment (the cumbersome nature of early catapults and ballista made their use as field artillery difficult, but they were used that way at times), foot skirmishers using sling and javelin, light harassment cavalry, or the Roman legion (which divided the phalanx into a lot of miniature phalanxes that were trained for independent maneuver). Use of terrain also helped a great deal - the phalanx worked best on mostly-flat ground, so luring (or forcing) the phalanx to fight on very uneven terrain greatly hurt the cohesion that was central to the phalanx's power.