The extent to which the answer to your question is no is analysed by Milnor's exact sequence. You can write $M$ as the colimit of a sequence $M_n \subset M_{n+1}$ of cofibrations with $M_n$ compact (at least if $M$ is a manifold but much more generally). Then there is a "short exact sequence" of pointed sets $$ \{1\} \to \textstyle{\lim^1_n} [\Sigma M_n, N]_* \to [M,N]_* \to \lim_n [M_n,N]_* \to \ast $$ (in the usual sense that the map of pointed sets on the right is surjective and its fibers are orbits of the action of the group $\lim^1$ which acts on the set in the middle). Brayton Gray used this sequence to construct the example that Mark Grant mentions in the comments above in [this paper][1] (since $S^3$ is simply connected there is no difference between pointed and unpointed homotopy classes). Another reference for the Milnor exact sequence is Bousfield and Kan, Homotopy Limits, Completions and Localizations, Corollary IX.3.3. [1]: https://www.sciencedirect.com/science/article/pii/0040938366900085