The issue is that you are not taking into account the support. The density of a continuous uniform random variable $X$ on the interval $[a,b]$ is actually $$f_X(x) = \frac{1}{b-a} \mathbb{I} (a \le x \le b) = \begin{cases} \frac{1}{b-a}, & a \le x \le b \\ 0, & \text{otherwise}. \end{cases}$$
Consequently, the likelihood of an IID sample $\boldsymbol x = (x_1, x_2, \ldots, x_n)$ for unknown parameters $a, b$ will be
$$\mathcal L(a, b \mid \boldsymbol x) = \prod_{i=1}^n f_{X_i}(x_i) = \frac{1}{(b-a)^n} \mathbb{I} (a \le x_1, x_2, \ldots, x_n \le b).$$ Note how the use of the indicator function $\mathbb 1$ changes the likelihood: we have now made it explicit that the likelihood is zero that any observations $x_i$ will be outside the interval $[a,b]$.
So now if we attempt to maximize this likelihood, we must take this additional restriction into account. But before we do so, we can simplify the indicator function by noting that if $a \le x_1, x_2, \ldots, x_n \le b$, that is to say, every observation must be between $a$ and $b$, this is equivalent to saying that the smallest observation $x_{(1)} = \min_i x_i$ must not be smaller than $a$, and the largest observation $x_{(n)} = \max_i x_i$ not be larger than $b$. So we may write our likelihood as
$$\mathcal L(a, b \mid \boldsymbol x) = (b-a)^{-n} \mathbb{I} (x_{(1)} \ge a) \mathbb{I} (x_{(n)} \le b).$$ You may ask, for instance, what happens if $x_{(1)} > b$. That will still satisfy the first indicator, but it won't satisfy the second, since $x_{(1)} \le x_{(n)}$. Similarly, if $x_{(n)} < a$, then the second indicator is satisfied but not the first.
With this characterization of the likelihood, it is now very easy to see the MLE. For a fixed $b$ and sample $\boldsymbol x$, the choice of $a$ that maximizes $\mathcal L$ will be the one that makes $a$ as large as possible without violating the condition $x_{(1)} \ge a$, since $(b-a)^{-n}$ is an increasing function of $a$. Similarly, for a fixed $a$ and sample $\boldsymbol x$, the choice of $b$ that maximizes $\mathcal L$ will be the one that makes $b$ as small as possible without violating the condition $x_{(n)} \le b$, since $(b-a)^{-n}$ is a decreasing function of $b$. So our (joint) MLE will be $$\hat a = x_{(1)} = \min_i x_i, \quad \hat b = x_{(n)} = \max_i x_i.$$