Here is what have tried to solve the following integral (without any contour integration)
$$I = \int_{0}^{2\pi} e^{\cos x}\cos(\sin x) \mathrm{d}x$$
$$I = \int_{0}^{2\pi} e^{\cos x}\mathrm{Re}\{e^{i\sin x}\} \mathrm{d}x = \mathrm{Re}\Bigg\{\int_{0}^{2\pi}e^{\cos x + i\sin x} \mathrm{d}x\Bigg\} = \mathrm{Re}\Bigg\{\int_{0}^{2\pi}e^{e^{ix}} \mathrm{d}x\Bigg\}$$
Now taking $e^{ix} = u$, one gets $ie^{ix} \mathrm{d}x = \mathrm{d}u$, thereby $\mathrm{d}x = \frac{\mathrm{d}u}{iu}$.
Since $e^{0i} = e^{2\pi i} = 1$, we end up with
$$I = \mathrm{Re}\Bigg\{\frac{1}{i}\int_{1}^{1}\frac{e^{u}}{u} \mathrm{d}u\Bigg\} = 0$$
which is obviously incorrect because of how the integrand of $I$ looks like:
What am I doing wrong here?

When we wrote $\int_a^b f(x) dx$, by default, $x$ goes along the real axis, and $x$ cannot leave real axis. If we are more rigorous, we should still use a path notation (or called contour), such as $C_1$, where $C_1$ is the straight line along real axis from $x=a$ to $x=b$. Namely, $$\int_{C_1} f(x) dx$$
and $C_1$ should reflect the actual trace of the integation variable $x$.
For your case, $x$ goes from $0$ to $2\pi$ along the real axis, no problem.
But when you let $u=e^{ix}$, $u$ is NOT along real axis anymore, $u$ leaves the real axis, goes along the unit circle, from $(1,0)$ and back to $(1,0)$, so you cannot just put the inital point and endpoint, but need to put the actual trace, namely the unit circle $C$
$$\oint_C g(u) du$$