I have seen the following proof for the power rule:
$$ \begin{align*} y &= x^n\\ \ln(y) &= n\ln(x)\\ \frac{d}{dx}\ln(y) &= \frac{d}{dx}(n\ln(x))\\ \frac{y'}{y} &= \frac{n}{x}\\ y' &= nx^{n-1} \end{align*} $$
However, what I don't understand is how is this proof valid if $y$ may be negative and then $\ln(y)$ would not be defined. Even if $y'$ is indeed $nx^{n-1}$, isn't this proof a wrong way to achieve the right answer?