This is probably not your fault, since I've seen way too many math textbooks with outright errors about this.
As @fleablood noted in their comment to your question, exponentiation is not always well-defined, but you can make it well-defined by making some more or less arbitrary choices. Textbooks that stick to the real numbers usually make choices so that $ a ^ n $ has a single well-defined value whenever $ a $ is positive, $ a $ is zero and $ n $ is positive (or maybe zero), or $ a $ is negative and $ n $ is rational with an odd denominator in lowest terms. Then if they introduce complex numbers, they'll allow the denominator of $ n $ to be $ 2 $ in the last case (and sometimes consider more general values). All of this is fine as far as it goes.
But they also want to state some identities about exponentiation, such as $ ( a ^ m ) ^ n = a ^ { m n } $ (which implies that $ ( a ^ m ) ^ n = ( a ^ n ) ^ m $, since $ m n = n m $). This identity is valid in the sense that you can always make appropriate choices in the definition of exponentiation to make the equation true[*]. Unfortunately, the choices in the previous paragraph will not always work! With those choices, the identity holds if $ a $ is positive, it holds if $ m $ and $ n $ are both integers, and it holds if $ m $ is $ 1 / 2 $ and $ n $ is an integer; but it fails in other cases, such as if $ a $ is negative, $ m $ is an even integer, and $ m n $ is odd (which can happen if $ n $ is fractional).
In particular, if $ a = - 1 $, $ m = 2 $, and $ n = 1 / 2 $, then the identity fails; $$ ( a ^ m ) ^ n = \big ( ( - 1 ) ^ 2 ) ^ { 1 / 2 } = 1 ^ { 1 / 2 } = 1 \text , $$ while $$ a ^ { m n } = ( - 1 ) ^ { 2 \cdot 1 / 2 } = ( - 1 ) ^ 1 = - 1 \text . $$ (On the other hand, if $ a = - 1 $, $ m = 1 / 2 $, and $ n = 2 $, then the identity holds; $ ( a ^ m ) ^ n $ and $ a ^ { m n } $ are both $ - 1 $ in that case.)
[*] If $ a $ is zero and $ b $ is negative, then you have to go beyond the complex numbers to the extended complex numbers to define $ a ^ b $, but you can still make this identity hold.