The Shulchan Aruch writes in OC 366:2 that the Eiruv must be placed in an area that is livable and not in a hut smaller that 4 amos by 4 amos, so your concern would appear to be justified.
However, the Biur Halacha there quotes the Tosfos Shabbos that a small room that opens into a larger room is acceptable, as we view the Eiruv as if it is located in the larger, livable location. This would include a closet, and it would seem to be, in fact, an acceptable option.
Nevertheless, the Biur Halacha concludes that he is not convinced by the logic of the Tosafos Shabbos, and he remains without a decisive conclusion. Certainly, it would be preferable to be Machmir.