In the anime, I remember Kaguya coming to Earth and later she castes Infinite Tsukuyomi on the people. But later we are shown that Kaguya is sealed and is formed into the moon. Then what did she cast Tsukuyomi on the first place, as the Infinite Tsukuyomi requires a moon?
Yes, there was no moon when Kaguya arrived on Earth. And for the Infinite Tsukuyomi to be activated, the presence of a moon is a primary condition.
So, in Naruto: Shippūden episode 460, Kaguya activates the Infinite Tsukuyomi. She does so by using her space time jutsu Yomotsu Hirasaka to open a portal and use a moon from somewhere else.
The animation of the portal opening is shown only for a split second.