Example of a ring without Invariant Basis Property
Solution 1:
No, if the ring is commutative, yes, if the ring is noncommutative.
The easiest counterexample is the endomorphism ring $R$ of $V=F^{(\omega)}$, where $F$ is a field and $F^{(\omega)}$ denotes a direct sum of countably many copies of $F$ (as vector space). Let homomorphisms act on the left, so $V$ becomes a left $R$-module.
Then $R\cong R^2$ as left modules, because $$R^2\cong\operatorname{Hom}_F(V,V\oplus V)\cong\operatorname{Hom}_F(V,V).$$
A theorem by A. L. S. Corner says that for every $k>0$ there exists a (noncommutative) ring $R$ such that $R^m\cong R^n$ (for $m,n>0$) as left modules if and only if $m\equiv n\pmod{k}$.
If the ring $A$ is commutative (with unity), then take a maximal ideal $P$; then from $A^m\cong A^n$ it follows $(A/P)^m\cong(A/P)^n$ as $A/P$-modules. Invariance of dimension for vector spaces makes you conclude that $m=n$.
Rings $R$ with the property that $R^m\cong R^n$ as left modules implies $m=n$ are said to have invariant basis number (on the left).
Solution 2:
A ring $A$ is said to have (right) invariant basis property (IBP) if for any integers $s, t \geq 0$,
$$ A^{\oplus s} \cong A^{\oplus t} \Rightarrow s = t $$
where the above isomorphism is as right $A$-modules.
Any non-zero commutative ring, any left Noetherian ring, and any semi-local ring satisfies IBP. The following link might be useful: Cohn, P. M. - Some remarks on the invariant basis property. Topology 5 (1966) 215–228.