Solution (source code)

= Solution

The <Rellich-Kondrachov compactness theorem> states in particular that for a bounded open set $U\subset\mathbb R^n$ with smooth boundary, the embedding
$$
H^1(U)\hookrightarrow L^2(U)
$$
is compact. More generally it is compact into $L^q(U)$ for $1\leq q<2n/(n-2)$ when $n\geq3$, for every finite $q$ when $n=2$, and into $C^0(\overline U)$ in dimension one.

Boundedness is essential. Choose a nonzero $\varphi\in C_c^\infty(\mathbb R^n)$ and set $u_k(x)=\varphi(x-ke_1)$ with pairwise disjoint supports. Their $H^1(\mathbb R^n)$ norms are equal, while
$$
\lVert u_j-u_k\rVert_2^2=2\lVert\varphi\rVert_2^2
$$
for $j\ne k$. Thus no subsequence converges in $L^2$.