Conditions on Hartshorne exercise II.7.1 Hartshorne, "Algebraic Geometry," Exercise II.7.1, reads:

Let $(X, \mathcal{O}_X)$ be a locally ringed space, and let $f : \mathscr{L} \to \mathscr{M}$ be a surjective map of invertible sheaves on $X$.  Show that $f$ is an isomorphism.

To prove this, I note that a morphism of sheaves is injective (resp. surjective) iff it is injective (resp. surjective) on stalks.  Thus $f_P$ is surjective for each $P \in X$.  Since $\mathscr{L}$ and $\mathscr{M}$ are invertible, $\mathscr{L}_P \cong \mathscr{M}_P \cong \mathcal{O}_{X, P}$ as $\mathcal{O}_{X, P}$-modules.  From commutative algebra, a surjective endomorphism of finitely-generated modules over any ring is in fact an automorphism, so $f$ is an isomorphism on stalks and thus an isomorphism of sheaves.
This argument sounds fine to me, but now I'm worried because I didn't use many of the conditions in the problem -- I could weaken it to an arbitrary (rather than locally-) ringed space, to any locally free sheaves of the same rank or even to something a bit weaker (namely that $\mathscr{L}$ and $\mathscr{M}$ are locally isomorphic), etc.
Have I missed something here?  Or does the result hold in much wider generality without any modification?
 A: This is elementary undergraduate algebra and has  nothing to do with local rings nor Nakayama:  
One reduces  to show  that given a commutative ring $A$, any surjective $A$-linear map $f:A\to A$ is in fact bijective.
Since $f(x)=f(x\cdot 1)=x\cdot f( 1)$, the map $f$ has the form $f(x)=u\cdot x$ (with $u:=f(1)$).
Since $f$ is surjective, there exists $v\in A$ with $1=f(v)=u\cdot v$ .
This implies that $u$ is invertible and $f$ is thus bijective with inverse $f^{-1}(y)= v\cdot y$ .
A: Daniel McLaury, you are right. The same proof works in the following generality: If $X$ is a ringed space, $F,G$ are $\mathcal{O}_X$-modules such that for every $x \in X$ there is some isomorphism $F_x \cong G_x$ and this $\mathcal{O}_{X,x}$-module is finitely generated, then every epimorphism $F \to G$ is an isomorphism. The reason is that $F_x \to G_x$ is an isomorphism for every $x \in X$, by Nakayama. Of course this argument simplifies when $F,G$ are invertible, see Georges' answer.
A: You have used that $f_P$ is an endomorphism.  At the very least, you need to assume that $\mathcal{L}$ and $\mathcal{M}$ are locally isomorphic.
