My course notes have,
For the particle confined to $x\in[0,a]$, the stationary state wavefunctions are $$\psi(x,t)=\begin{cases}A_n\exp\left(-\frac{i\hbar n^2\pi^2t}{2ma^2}\right)\sin\left(\frac{2\pi x}{a}\right) &\text{if }0<x<a\\0&\text{otherwise,}\end{cases}$$ where $n=1,2,3,\dots$ and $A_n$ are undetermined complex constants.
To normalise $\psi_n(x,t)$ we choose the coefficient $A_n$ so that $$\int_{-\infty}^\infty|\psi_n(x,t)|^2\text{ d}x=\int_0^a|\psi_n(x,t)|^2\text{ d}x=1.$$ Plugging the stationary state wavefunctions in gives $$|A_n|^2=\frac{2}{a},\text{ for all }n=1,2,3,\dots$$
I guess this is a simple question, but where did this $2$ come from? My thinking is \begin{align} & \begin{aligned} |\psi_n(x,t)|^2 & = \left|A_n\exp\left(-\frac{i\hbar n^2\pi^2t}{2ma^2}\right)\sin\left(\frac{2\pi x}{a}\right)\right|^2 && (1) \\ & = |A_n|^2\cdot\left|\exp\left(-\frac{i\hbar n^2\pi^2t}{2ma^2}\right)\right|^2\cdot\left|\sin\left(\frac{2\pi x}{a}\right)\right|^2 && (2) \\ & = |A_n|^2\cdot1\cdot1\text{ (in the complex plane)} && (3) \\ & = |A_n|^2 && (4) \end{aligned} \\[0.5em] \therefore\;&\begin{aligned}[t] 1 & = \int_0^a|\psi_n(x,t)|^2\text{ d}x && \hspace{14.25em} (5) \\ & = \int_0^a|A_n|^2\text{ d}x && \hspace{14.25em} (6) \\ & = |A_n|^2a && \hspace{14.25em} (7) \end{aligned} \\[0.5em] \therefore\;& |A_n|^2=\frac{1}{a}. \hspace{20.75em} (8) \end{align} What's gone wrong?
Did you actually attempt the integration of the squared sine in line $(2)$?
$$\begin{align} \int_{x=0}^a \sin^2 \frac{2\pi x}{a} \, dx &= \int_{u=0}^{\pi} (\sin^2 2u) \frac{a}{\pi} \, du & \left( x = \frac{a}{\pi} u, \quad dx = \frac{a}{\pi} \, du \right) \\ &= \frac{a}{\pi} \left[\frac{u}{2} - \frac{1}{8} \sin 4u \right]_{u=0}^\pi \\ &= \frac{a}{\pi} \frac{\pi}{2} \\ &= \frac{a}{2}. \end{align}$$
The fact that the complex exponential term has magnitude $1$ is a trivial consequence of the fact that $|e^{i\theta}| = 1$ for any angle $\theta$.