It is impossible to produce an example of a finitely generated flat $R$-module that is not projective when $R$ is an integral domain. See: Cartier, "Questions de rationalité des diviseurs en géométrie algébrique," here, Appendice, Lemme 5, p. 249. Also see Bourbaki Algèbre Chapitre X (Algèbre Homologique, "AH") X.169 Exercise Sect. 1, No. 13. I also sketch an alternate proof that there are no such examples for $R$ an integral domain below.
Observe that, for finitely generated $R$-modules $M$, being locally free in the weaker sense is equivalent to being flat [Bourbaki, AC II.3.4 Pr. 15, combined with AH X.169 Exercise Sect. 1, No. 14(c).]. ($R$ doesn't have to be noetherian for this, though many books seem to assume it.)
There's a concrete way to interpret projectivity for finitely generated flat modules. We begin by translating Bourbaki's criterion into the language of invariant factors. For any finitely generated flat $R$-module $M$ and any nonnegative integer $n$, the $n$-th invariant factor $I_n(M)$ is the annihilator of the $n$-th exterior power of $M$.
Lemma. (Bourbaki's criterion) A finitely generated flat $R$-module $M$ is projective if and only if, for any nonnegative integer $n$, the set $V(I_n(M))$ is open in $\mathrm{Spec}(R)$.
This openness translates to finite generation.
Proposition. If $M$ is a finitely generated flat $R$-module, then $M$ is projective iff its invariant factors are finitely generated.
Corollary. The following conditions are equivalent for a ring $R$: (1) Every flat cyclic $R$-module is projective. (2) Every finitely generated flat $R$-module is projective.
Corollary. Over an integral domain $R$, every finitely generated flat $R$-module is projective.
Corollary. A flat ideal $I$ of $R$ is projective iff its annihilator is finitely generated.
Example. Let me try to give an example of a principal ideal of a ring $R$ that is locally free in the weak sense but not projective. Of course my point is not the nature of this counterexample itself, but rather the way in which one uses the criteria above to produce it.
Let $S:=\bigoplus_{n=1}^{\infty}\mathbf{F}_2$, and let $R=\mathbf{Z}[S]$. (The elements of $R$ are thus expressions $\ell+s$, where $\ell\in\mathbf{Z}$ and $s=(s_1,s_2,\dots)$ of elements of $\mathbf{F}_2$ that eventually stabilize at $0$.) Consider the ideal $I=(2+0)$.
I first claim that for any prime ideal $\mathfrak{p}\in\mathrm{Spec}(R)$, the $R_{\mathfrak{p}}$-module $I_{\mathfrak{p}}$ is free of rank $0$ or $1$. There are three cases: (1) If $x\notin\mathfrak{p}$, then $I_{\mathfrak{p}}=R_{\mathfrak{p}}$. (2) If $x\in\mathfrak{p}$ and $\mathfrak{p}$ does not contain $S$, then $I_{\mathfrak{p}}=0$. (3) Finally, if both $x\in\mathfrak{p}$ and $S\subset\mathfrak{p}$, then $I_{\mathfrak{p}}$ is a principal ideal of $R_{\mathfrak{p}}$ with trivial annihilator.
It remains to show that $I$ is not projective as an $R$-module. But its annihilator is $S$, which is not finitely generated over $R$.
[This answer was reorganized on the recommendation of Pete Clark.]
No, being torsion is not a local property, and I can give a counterexample. [Edit: This took some doing, with my initial answer containing a serious flaw. After completely reworking the construction, this should work now. Apologies for the length of this answer, but I don't see any quick constructions].
The idea is to construct a ring $R$ and an ideal $I$ contained in the zero divisors of $R$, and $f_1,f_2\in R$ satisfying $f_1+f_2=1$ such that $I_{f_i}$ contains a regular element of $R_{f_i}$ for each $i$.
This provides a counterexample to the question by taking the module $M=R/I$ and $m=I+1$. Then, ${\rm ann}(m)=I$ consists of zero divisors, so $m$ is not torsion. However, mapping $m$ into $M_{f_i}$ takes ${\rm ann}(m)$ to $I_{f_i}$, which contains regular elements of $R_{f_i}$. So, $m$ is torsion in each $M_{f_i}$.
This does get rather involved, so let's start simple and construct an example showing that being torsion is not a stalk-local property.
Choose a field $k$, set $A=k[X_0,X_1,X_1,X_2,\ldots]$ and let $J$ be the ideal generated by $X_iX_j$ for $i\not=j$ and $X_i(X_i-1)$ for $i\ge1$. Then, $R=A/J$ is the $k$-algebra generated by elements $x_0,x_1,\ldots$ satisfying the relations $x_ix_j=0$ for $i\not=j$ and $x_i(x_i-1)=0$ for $i\ge1$. Let $I\subseteq R$ be the ideal generated by $x_0,x_1,\ldots$.
We can see that $x_i\not=0$ by considering the $k$-morphism $A\to k$ taking $X_j$ to 1 (some fixed $j$) and $X_i$ to 0 for $i\not=j$. This takes $J$ to 0, so it defines a $k$-morphism $R\to k$ mapping $x_j$ to 1, so $x_j\not=0$. Then, every $a\in I$ satisfies $ax_j=0$ for large $j$, showing that it is a zero divisor. Also, the $k$-morphism $A\to k$ taking each $X_i$ to zero contains $J$ in its kernel, and defines a morphism $R\to\mathcal{k}$ with kernel $I$, showing that $R/I\cong k$. So $I$ is a maximal ideal. For any prime $\mathfrak{p}$ we either have $\mathfrak{p}\not=I$, in which case the non-empty set $I\setminus\mathfrak{p}$ maps to units (and hence, regular elements) in $R_{\mathfrak{p}}$. Or, we have $\mathfrak{p}=I$ in which case $x_i-1$ maps to a unit and $x_i$ goes to zero in $R_{\mathfrak{p}}$ ($i\ge1$). So, $R_{\mathfrak{p}}\cong k[X]$ with $x_0$ going to the regular element $X$. This shows that $I$ contains regular elements in the localization at any prime, giving the required counterexample for the stalk-local case.
Now, let's move on to the full construction of the counterexample showing that being torsion is not a local property. Simply guessing a set of generators and relations as for the stalk-local case didn't work out so well. Instead, I will start with a simple example of a polynomial ring and then transform it in such a way as to give the properties we are looking for. I find it helpful to first fix the following notation: Start with the base (polynomial) ring $R=\mathbb{Z}[x,y,z]$. A (commutative, unitial) R-algebra is simply a ring with three distinguished elements $x,y,z$, and a morphism of R-algebras is just a ring homomorphism respecting these distinguished elements. For an R-algebra $A$, define $K(A)\subseteq A$ to be the smallest ideal such that, for all $a\in A$,
$$
\begin{align}
ax\in K(A)&\Rightarrow az\in K(A),\\\\
ay\in K(A)&\Rightarrow a(1-z)\in K(A).
\end{align}
$$
In particular, $K(A)=0$ implies that $x$ is a regular element in the localization $A_z$ and $y$ is a regular element in $A_{1-z}$. If we can construct such an example where the ideal $Ax+Ay$ consists purely of zero divisors, then that will give the counterexample needed. The idea is to start with $A=\mathbb{Z}[x,y,z]$ and transform it using the following steps.
- Force the elements of $I=Ax+Ay$ to be zero divisors. So, for each $a\in I$, add an element $b$ to $A$ in as free a way as possible such that $ab=0$. Adding elements to $A$ also has the effect of adding elements to $I$. So, this step needs to be iterated to force these new elements of $I$ to also be zero divisors.
- Replace $A$ by the quotient $A/K(A)$ to force the condition $K(A)=0$.
The first step above is easy enough. However, we do need to be careful to check that the second step does not undo the first. Suppose that $a\in A$ is a zero divisor, so that $ab=0$ for some non-zero $b$. It is possible that taking the quotient in the second step above takes $b$ to zero, so that $a$ becomes a regular element again. To get around this, we need some stronger condition on $b$ which implies $b\not=0$ and is also stable under taking the quotient. Note that $A(1-b)$ being a proper ideal or, equivalently, $A/(1-b)$ being nontrivial, will imply that $b\not=0$. In turn, this is implied by $K(A/(1-b))$ being a proper ideal. As it turns out, this property of $b$ does remain stable under each of the steps above, and can be used to show that this construction does give the counterexample required. However, note that if $ab=0$ and $K(A/(1-b))$ is proper, then $a=a(1-b)\in A(1-b)$, from which we can deduce that $K(A/(a))$ is a proper ideal. This necessary condition is unchanged by either of the steps above, so we had better check that elements $a\in Ax+Ay$ in our R-algebra do satisfy this from the outset. I'll make the following definition: $A$ satisfies property (P) if $K(A/(a))$ is proper for every $a\in Ax+Ay$. As it turns out, polynomial rings do satisfy this property and, consequently, the construction outlined above works fine.
Now on to the details of the argument.
(1) Let $f\colon A\to B$ be an R-morphism. Then $f(K(A))\subseteq K(B)$. Furthermore,
- If $I\subseteq A$, $J\subseteq B$ are ideals with $f(I)\subseteq J$ and $K(B/J)$ is proper, then $K(A/I)$ is proper.
- If $B$ satisfies (P) then so does $A$.
As $f^{-1}(K(B))$ satisfies the defining properties for $K(A)$ (other than minimality), it contains $K(A)$. In particular, if $K(B)$ is proper then $K(A)\subseteq f^{-1}(K(B))$ is proper. Next, if $f(I)\subseteq J$ are ideals, then $f$ induces an R-morphism $A/I\to B/J$ so, if $K(B/J)$ is proper then so is $K(A/I)$.
If $B$ satisfies property (P) and $a\in Ax+Ay$ then $f(a)\in Bx+By$ and $K(B/f(a))$ is proper. So, $K(A/(a))$ is proper and $A$ also satisfies property (P).
(2) If $A$ is a non-trivial ring then the polynomial ring $R\otimes A\cong A[x,y,z]$ satisfies (P).
As $A$ is non-trivial, it must have a maximal ideal $\mathfrak{m}$. Applying (1) to the R-morphism $A[x,y,z]\to(A/\mathfrak{m})[x,y,z]$ reduces to the case where $A=k$ is a field. Then, letting $\bar k$ be the algebraic closure, applying (1) to $k[x,y,z]\to\bar k[x,y,z]$ reduces to the case where $A=k$ is an algebraically closed field.
Now set $B=k[x,y,z]$ and choose $a\in Bx+By$. The idea is to look at the morphism $\theta\colon B/(a)\to k$ taking $x,y,z$ to some $x_0,y_0,z_0\in k$ with $a(x_0,y_0,z_0)=0$. As long as these satisfy $ux_0=0\Rightarrow uz_0=0$ and $uy_0=0\Rightarrow u(1-z_0)=0$ (all $u\in k$) then $K(B/(a))$ will be contained in the kernel of $\theta$, so will be proper. For this to be the case it is enough that both ($x_0\not=0$ or $z_0=0$) and ($y_0\not=0$ or $z_0=1$).
Case 1: We can find $a(x_0,y_0,z_0)=0$ such that $x_0y_0\not=0$. This satisfies the required condition.
Case 2: Whenever $a(x_0,y_0,z_0)=0$ then $x_0y_0=0$. This means that $xy$ is contained in the radical ideal generated by $a$, so $a$ divides $x^ry^r$ some $r\ge1$. Then $a$ is a multiple of $x$ or $y$ and one of $(x_0,y_0,z_0)=(0,1,0)$ or $(1,0,1)$ satisfies the required condition. So, $K(B/(a))$ is proper.
Next, we construct extensions of the R-algebra forcing elements of $Ax+Ay$ to be zero-divisors.
(3) If $A$ satisfies (P), then we can construct an R-morphism $f\colon A\to B$ with a left-inverse and such that, for every $a\in Ax+Ay$, there is a $b\in B$ with $ab=0$ and $K(B/(1-b))$ is proper.
To construct the morphism, set $I=Ax+Ay$ and let $(X_a)_{a\in I}$ be indeterminates over $A$. Let $J$ be the ideal in $A[(X_a)_{a\in I}]$ generated by $(aX_a)_{a\in I}$. Then define $B=R[(X_a)_{a\in I}]/J$ and let $f$ be the canonical homomorphism. Its left inverse is the map taking $X_a$ to 0.
Now, for a fixed $a\in I$, set $b=J+X_a$, so $ab=0$. Consider the morphism $A[(X_c)_{c\in I}]\to A\to A/(a)$ taking each $X_c$ to 0 (for $c\not=a$) and $X_a$ to 1. As its kernel contains $J$, it defines a morphism $g\colon B\to A/(a)$, which takes $b$ to one. Therefore, the ideal $B(1-b)$ maps to 0 and, as $K(A/(a))$ is proper, (1) says that $K(B/(1-b))$ is proper.
(4) If $A$ satisfies (P), then we can construct an R-morphism $f\colon A\to B$ such that, for every $a\in Bx+By$ there is a $b\in B$ with $ab=0$ and $K(B/(1-b))$ is proper.
Set $A_0=A$ and use (3) to construct a sequence of extensions $f_i\colon A_i\to A_{i+1}$ with left inverses such that, for every $a\in A_ix+A_iy$ there is a $b\in A_{i+1}$ with $ab=0$ and $K(A_{i+1}/(1-b))$ is proper. Note that, as each $f_i$ has a left inverse, (1) says that $A_{i+1}$ satisfies (P) whenever $A_i$ does. So, we can keep applying (3) to build up the entire sequence of extensions.
We now take the colimit $B={\rm colim}A_i$ and let $f$ be the induced morphism (i.e, if we consider $A_i\subseteq A_{i+1}$ then $B$ is the union and $f$ is inclusion). As each $A_i\to B$ has a left-inverse, (1) shows that the required properties for $B$ are inherited from the individual $A_i$.
(5) Suppose that $A$ satisfies the following: for every $a\in Ax+Ay$ there is a $b\in A$ with $ab=0$ and $K(A/(1-b))$ is proper. Then, the R-algebra $B=A/K(A)$ satisfies the same property, and also $K(B)=0$.
That $K(B)=0$ follows quickly from the definition of $K$.
Suppose $a\in Ax+Ay,b\in A$ are such that $ab=0$ and $K(A/(1-b))$ is proper. Set $C=A/(1-b)$, so that $C/K(C)$ is not trivial. By (1), the canonical morphism $A\to C$ maps $K(A)$ into $K(C)$. So, it induces a morphism $B\to C/K(C)$. This takes $1-b$ to zero, so it induces an R-morphism $B/(1-b)\to C/K(C)$. As $K(C/K(C))=0$, (1) implies that $K(B/(1-b))$ maps to zero, so is proper.
(6) If $B$ is the R-algebra constructed in (5), then $I=Bx+By$ contains only zero-divisors but $x,y\in I$ map to regular elements in $R_z$ and $R_{1-z}$ respectively.
For any $a\in I$ there is a $b\in B$ with $ab=0$ and $K(B/(1-b))$ proper. In particular, $(1-b)$ must be a proper ideal, so that $b\not=0$ and $a$ is a zero divisor.
Finally, the property $K(B)=0$ implies that $x$ is regular in $B_z$ and $y$ is regular in $B_{1-z}$.
Best Answer
For a finitely generated module $M$ over a commutative ring $R$, the first definition gives a rank function $r_M: \operatorname{Spec} R \rightarrow \mathbb{N}$, whereas the third definition gives $r_M((0))$.
When $M$ is projective, $r_M$ is locally constant, so when $\operatorname{Spec} R$ is connected -- so when $R$ is a domain -- $r_M$ is constant and may be identified with its value at $(0)$. I think you are asking for reassurance that for finitely generated non-projective modules over a domain, the rank function need not be constant. That's certainly true: take $\mathbb{Z}/p\mathbb{Z}$ over $\mathbb{Z}$ (or even over $\mathbb{Z}_p$): then the rank function is $1$ at $(p)$ and otherwise $0$, so the first definition really is not the same as the third.
Is this a problem? I don't think so. Asking for terminology in mathematics to be globally consistent seems to be asking for too much: even more basic and central terms like "ring" and "manifold" do not have completely consistent definitions across all the mathematical literature: rather, they overlap enough to carry a common idea. That is certainly the case here.
Similarly, asking which of 1) and 3) is "right" doesn't seem so fruitful. It is true that the first definition records more information than the third definition. But it's just terminology, and it is often useful to have a term which records exactly the information in the third definition: e.g. the "rank of an abelian group" is a very standard and useful notion, and
usuallyoften it means 3). (I am a number theorist, and in number theoretic contexts this definition of rank is quite standard. Apparently it is less so elsewhere...) For a finitely generated module over a PID, of course the rank in the sense of 3) is exactly what you need in addition to the torsion subgroup in order to reconstruct the module. In this context the rank function 1) gives some information about the torsion but not complete information -- e.g. $\mathbb{Z}/p\mathbb{Z}$ and $\mathbb{Z}/p^2\mathbb{Z}$ have the same rank function -- so the rank function as in 1) does not seem especially natural or useful. I am (almost) sure there are other contexts where it would be natural and useful to think in terms of the rank function as in 1).Added: Following quid's comments I checked out Fuchs's text on infinite abelian groups, and indeed the rank of an arbitrary abelian group is defined in a way so as to take $p$-primary torsion into account. (I simply didn't know this was true.) Thus the rank defined there would be the sum over all the values of the rank function in the sense of 1).
All this seems to indicate, even more than my answer, that different notions of rank proliferate.
Added Later: Quid also suggests consideration of the quantity $\operatorname{mg}(M)$, the minimal number of generators of an $R$-module $M$: this is a cardinal invariant which is (clearly) finite if and only if $M$ is finitely generated. Let $R$ be a Dedekind domain with fraction field $K$. For a maximal ideal $\mathfrak{p}$ of $R$ and a finitely generated $R$-module $M$, let $M[\mathfrak{p}^{\infty}]$ be the submodule of $M$ consisting of elements annihilated by some power of $\mathfrak{p}$. Then $M[\mathfrak{p}^{\infty}]$ is a finitely generated torsion module over the DVR $R_{\mathfrak{p}}$ and is thus a direct sum of $\operatorname{mg}(M[\mathfrak{p}^{\infty}])$ copies of $R_{\mathfrak{p}}/\mathfrak{p}^k R_{\mathfrak{p}}$. Let us define $tr(M,\mathfrak{p})$ to be this number of copies. (When $M$ is infinitely generated I believe one should also count copies of $K_{\mathfrak{p}}/R_{\mathfrak{p}}$ in a certain sense in order to recover Fuchs's $p$-primary torsion rank in the $R = \mathbb{Z}$ case. Let me omit this for now.)
Now define
$R(M) = r_M((0)) + \sum_{\mathfrak{p} \in \operatorname{MaxSpec} R} tr(M,\mathfrak{p})$
When $R = \mathbb{Z}$ then $R(M) = \operatorname{mg}(M)$ is the "total rank" in Fuchs's sense. More generally $R(M) = \operatorname{mg}(M)$ when $R$ is a PID. However, I wanted to point out that in general the function $\operatorname{mg}$ behaves rather badly. This is discussed in $\S$ 6.5.3 of my commutative algebra notes. In particular, when $M$ is finitely generated projective, $\operatorname{mg}(M) \geq R(M) (= r_M((0))$ but can be larger. However, it is much more restricted than what I knew about before reading the comments on this question. In particular, it follows from the Forster-Swan Theorem that when $M$ is projective of rank $n$ then $\operatorname{mg}(M) \in \{n,n+1\}$. (In an earlier version of this answer I knew only that $\operatorname{mg}(M) \leq 2n-1$ and "guessed" that it could be that large over suitable Dedekind domains. Not a terrible guess, perhaps, but not the most educated one either...)