The Root of the Behavior
Chihuahuas are known to be fiercely territorial and protective. They will often bark constantly at anyone they perceive as a potential threat, and to them, that could be almost any stranger in your home, even friends of yours. They may also perceive someone as a threat for simply coming too close to you or moving in quick unpredictable motions. Another common cause of barking is simple separation anxiety. In the past, if a Chihuahua was separated from its pack they had few defensive mechanisms that would do them much good. Being as small and weak as they are, they needed to form tight groups to protect themselves, and one who was afraid to be away from the team were less likely to fall behind or walk away. These Chihuahuas, in turn, became far more likely to survive and so this genetic trait of separation anxiety was passed down from generation to generation whereas the Chihuahuas who did not possess this trait were more likely to die off.
Encouraging the Behavior
This could have been learned quite inadvertently and dog owners often make simple mistakes that have big impacts on canine behavior. For instance, if your Chihuahua is constantly barking for attention, and you start yelling at your Chihuahua or otherwise giving it attention, you have just trained your dog to bark at you to get what they want from you. The same goes for when you let your dog in the house, feed them, or give them treats or if you pet your dog when they come up to you and start barking for attention. All of these actually reward your canine for misbehaving.