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

1- In nlab (here http://ncatlab.org/nlab/show/rank), for quite general modules, the rank is defined locally at $p\in 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 here http://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 ?