The thermal expansion coefficient of van der Waals layered structures plays an important role in governing the thermal stability of high-performance electronic devices. Meanwhile, bubbles are frequently observed in the van der Waals layered structures due to the weak inter-layer interaction and the extremely small bending stiffness of the layered structure, but the effect of bubbles on the thermal expansion coefficient for layered structures remains unclear. We derive an analytic formula for the bubble effect on the length variation of the MoS2 layer. In the analytic derivation, the MoS2 layer is described by three mechanics models, including the elastic membrane theory, the nonlinear plate theory, and the linear plate theory. The gas inside the bubble is described by two types of state equations, including the ideal gas law and the generalized van der Waals equation. It is found that the nonlinear plate theory with the generalized van der Waals equation gives the most accurate description for the bubble effect, since MoS2 has a moderate bending stiffness. The analytic formula shows that the bubble can cause strong thermal contraction for few-layer MoS2 with increasing temperature. The analytic predictions are verified by comprehensive molecular dynamic simulations for few-layer MoS2 with different layer numbers and different gas molecule numbers. These results shall be valuable for understanding the thermal stability of functional devices based on the van der Waals layered structure.