They are expensive, but at the same time there is no need to spend crazy money, as there are lots of, and indeed some of the best EMTB's at sub 5k.
Having spent a lot of time in a past life going down a deep hole of having a big motorbike stable, with a lot of them modified, I would say though it is very hard to compare like to like, and that the average motorbike has pretty poor quality components in terms of suspension etc.
You can easily get into the high 20's by the time you have tricked out a bike to the equivalent of an S-Works or similar.
As some one else said if you stick Ohlins Factory kit, carbon wheels, etc etc on to a stock hi performance road bike you are going end up spending a lot of money quickly.
Really an S-Works or other high end bike is the equivalent of a Ducati Panigale Anniversario 916 at 37k vs a stock one at 12k which is more the level of an Expert.
Motorcycles also have a significant advantage interns of scale of manufacturing.