I have seen different definitions of a rank of a module $M$ over a commutative ring $R$.

1. [Here in nLab](http://ncatlab.org/nlab/show/rank), for quite general modules, the rank is defined locally at $p\in \mathrm{Spec}(R)$ as the dimension over the residue field $\kappa(p)$ of the $\kappa(p)$ vector space $M_p/pM_p$. When $M$ is of finite type, this is the local minimum of generators of $M_p$ over $R_p$.

2. The usual definition of the rank of a module when this module is projective of finite type is locally the rank of the free module $M_p$ over $R_p$. (see [mathoverflow.net/questions/29993](https://mathoverflow.net/questions/29993/rank-of-a-module) for instance). This function rank is locally constant, and therefore when $R$ is a domain, is the dimension of the vector space $M\otimes K$ over $K=R_0$.

3. When $R$ is a domain, Matsumura defines the rank of a quite general module $M$ by the maximum number of independent elements, that is the dimension of the vector space $M\otimes K$ over $K=R_0$.

Clearly, all these definitions coincides when $M$ is projective of finite type. When $R$ is a domain, and $M$ only of finite type, I see no reason why they should outside of the ideal $0$. I mean, in that case, to be projective for $M$ is the same as to be locally free. But if $M$ is not projective, the local minimum of generators of $M_p$ (definition 1) does not necessarily coincides with the global maximum of independent elements (definition 3), right?

Did I misunderstand something ? If I didn't, which definition should be used? And in the case of $M$ is only of finite type?

---

**EDIT**: In case the ring $R$ is noetherian and $M$ is of finite type, we have the following generalization of Matsumura's definition, if $Q$ is the total ring of fraction of $R$, with the equivalence of all the following statements:

1. $M$ is of rank $r$.

2. $M\otimes Q$ is a free rank $r$ module over $Q$.

3. The maximum number of independent elements of $M$ is $r$.

4. There exists a submodule $N$ of $M$ such that $M/N$ is torsion.

5. For all prime $p$ associated to $R$, $M_p$ is free of rank $r$ over $R_p$.

I like this last definition because this is the most global one when $R$ is not a domain (provided the module actually have a finite rank ...), and it is additive on exact sequence when two of the terms actually have finite rank.