TITLE: Conditions on Hartshorne exercise II.7.1
QUESTION [9 upvotes]: 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?

REPLY [4 votes]: 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.