# If a Gaussian surface is assumed in a non-uniform electric field and charge enclosed is zero, is the net electric flux coming out still zero?

Assume a Gaussian surface in a non-uniform electric field that is directed along X-axis. Say the field is getting weaker as we go along positive X direction and it's constant along Y and Z directions. Then, if the Gaussian surface is a cube and charge enclosed is zero, the electric flux coming into the surface is more than that flowing out. So, shouldn't the net electric flux be non-zero contradicting Gauss's law?

Does it mean such an electric field is impossible without a charge being distributed along the path?

Your question contains a contradiction. Basically the last sentence of your question is completely right. If $$\mathbf{E}=f(x)\hat{x}$$, then $$\frac{\rho}{\epsilon_0}=\nabla\cdot\mathbf{E}=f'(x)\neq 0$$ So in order to have an electric field that is only in the $$\hat{x}$$ direction and changes in magnitude with $$x$$, there must be charge present. With this electric field, Gaussian surfaces have nonzero flux because there is charge inside of them.