The knight was not beaten by gunpowder or longbows but by vast hordes of peasants with halberds.
Those peasant hordes showed up because changes in society enabled rulers to field these large armies.
In order to conduct in a long lasting war with large armies one needs a society with "backbone". The ability to lose a battle and still win a war is what makes a true great empire. Few ancients could to this, like the Roman empire, the Assyrian empire, the Mayans and so on.
Medieval Europe (where the knights ruled) was a largely fragmented bunch of small states, where a lost battle often resulted in a complete defeat.
WW1 style trench warfare emerged in the American Civil war and the Crimean war. Neither machine guns nor barbed wire where deployed in mass. Those wars where won by the ones who could hold out for longer.
Even WW2 was largely won by infantry and artillery, tanks and aircraft are way overrated.
Here are the German numbers for operation Barbarossa:
3.8 million personnel
3,350–3,795 tanks
3,030–3,072 other AFVs
2,770–5,369 aircraft
7,200–23,435 artillery pieces
17,081 mortars
600,000 horses
600,000 vehicles
There are a couple orders of magnitude between infantry and tanks.
The numbers for the attack on France look similar.
That tanks feature so prominently is due to propaganda (since those things look cool).
In modern societies, warfare is all about logistics, morale and the ability to take a punch.
Even a completely lopsided tech advantage can be negated if you survive the first few attacks.
That is one of the reasons why the Mongolians are gone but the Taliban are still there.