Someone may write a technical book for a niche community. The book may help others, build a portfolio etc. It doesn't need to earn lots of sales to be satisfying or useful.
I've published three books with a publisher, and the one I'm most proud of and which got the best reviews (19 ratings on Amazon, all 5 stars) is the most niche, and got the lowest sales numbers.
https://smile.amazon.com/Parsing-Perl-Regexes-Grammars-Recur... if anybody is interested.