  We prove the density of smooth functions in the modular topology in the
Musielak-Orlicz-Sobolev spaces essentially extending the results of Gossez
\cite{GJP2} obtained in the Orlicz-Sobolev setting. We impose new systematic
regularity assumption on $M$ which allows to study the problem of density
unifying and improving the known results in the Orlicz-Sobolev spaces, as well
as the variable exponent Sobolev spaces.
  We confirm the precision of the method by showing the lack of the Lavrentiev
phenomenon in the double-phase case. Indeed, we get the modular approximation
of $W^{1,p}_0(\Omega)$ functions by smooth functions in the double-phase space
governed by the modular function $H(x,s)=s^p+a(x)s^q$ with $a\in
C^{0,\alpha}(\Omega)$ excluding the Lavrentiev phenomenon within the sharp
range $q/p\leq 1+\alpha/N$. See \cite[Theorem~4.1]{min-double-reg1} for the
sharpness of the result.
