This exercise has no assumption on the boundedness of $D$, hence $\bar{D}$ is not guaranteed to be compact. Would this be essential for the assertion to be true?
Suppose the nonconstant function $f(z)$ is analytic in a domain $D$ and continuous on its closure. If $|f(z)|$ is constant on the boundary of $D$, prove that $f(z)$ has a zero in $D$.
The obvious approach is to assume by contradiction that $f$ has no zero in $D$. Then we can define a nonconstant analytic function $1/f$ in $D$, which gives us by the Maximum Modulus Theorem that $1/|f|$ does not attain a maximum in $D$. But how can I use this to reach a contradiction? I am stuck here and I would greatly appreciate any help.
The bounded case is the application of the maximum modulus principle mentioned in the comments, or in previous questions of this type. The assertion is untrue for unbounded $D$. If $D$ is the half plane and $f(z)=e^{iz}$, then $|f|$ is constant on $\partial D=\mathbb R$ but $f$ has no zeroes in $D$.