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.]
Here is an explicit counterexample:
Let $R^3$ be euclidean 3-space and $S^2$ the 2-sphere, embedded in $R^3$ as usual. Let $A$ be the ring of all real-valued continuous functions on $S^2$. Let $T$ be the $A$-module of all $R^3$-valued continuous functions on $S^2$ (so that $T\approx A^3$ is a free $A$-module). Let $M\subset T$ consist of all those functions $f$ such that $f(x).x=0$ for all $x$ (where "dot" denotes the usual inner product in $R^3$). Let $M'\subset T$ be the submodule generated by the identity function.
Observation 1: $M\oplus M'=T$. Thus, for any prime $P\subset A$, we have $M_P\oplus M'_P\approx T_P$. But over a local ring, any direct summand of a free module is free. Therefore $M_P$ is free.
Observation 2: $M$ can't be free. If it were, it would have a basis consisting of two triples $(f_1,f_2,f_3)$ and $(g_1,g_2,g_3)$ (the entries $f_i$ and $g_i$ being real-valued functions). This basis, together with the basis consisting of the single element $(x,y,z)$ for $M'$, would form a basis for $T$. It would follow that the matrix
$$\pmatrix{f_1&f_2&f_3\cr g_1&g_2&g_3\cr x&y&z\cr}$$
has unit determinant; in particular the determinant is a function on $S^2$ with no zeros.
But it is a fact from topology that if $f(x).x=0$ for all $x$, then there is some $x$ such that $f(x)=(f_1(x),f_2(x),f_3(x))=(0,0,0)$. Thus the determinant of the displayed matrix has a zero at $x$. This contradiction shows that $M$ is not free.
Now let $N$ be a free $A$-module of rank 2. Observation 1 shows that $M_P\approx N_P$ for all primes $P$; Observation 2 shows that $M$ is not isomorphic to $N$.
Best Answer
Dear roger123, let $R$ be a commutative ring and $M$ an $R$-module ( which I do not suppose finitely generated). In order to minimize the risk of misunderstandings, allow me to introduce the following terminology:
Locfree The module $M$ is locally free if for every $P \in Spec (R)$ there is an element $f \in Spec(R)$ such that $f \notin P$ and that $M_f$ is a free $R_f$ - module.
Punctfree The module $M$ is punctually free if for every $P \in Spec (R)$ the $R_{P} $ - module $M_P$ is free.
Fact 1 Every locally free module is punctually free. Clear.
Fact 2 Despite Wikipedia's claim, it is false that a punctually free module is locally free.
Fact 3 However if the punctually free $R$- module $M$ is also finitely presented, then it is indeed locally free.
Fact 4 A finitely generated module is locally free if and only it is projective.
Fact 5 A projective module over a local ring is free.This was proved by Kaplansky and is remarkable in that, let me repeat it, the module $M$ is not supposed to be finitely generated.
A family of counterexamples to support Fact 2 Let R be a Von Neumann regular ring. This means that every $r\in R$ can be written $r=r^2s$ for some $s\in R$. For example, every Boolean ring is Von Neumann regular. Take a non-principal ideal $I \subset R$. Then the $R$- module $R/I$ is finitely generated (by one generator: the class of 1 !), all its localizations are free but it is not locally free because it is not projective (cf. Fact 4) .The standard way of manufacturing that kind of examples is to take for R an infinite product of fields $\prod \limits_{j \in J}K_j$ and for $I$ the set of families $(a_j)_{j\in J}$ with $a_j =0$ except for finitely many $j$ 's.
Final irony In the above section on counterexamples I claimed that the $R$ - module $R/I$ is not projective.This is because in all generality a quotient $R/I$ of a ring $R$ by an ideal $I$ can only be $R$ - projective if $I$ is principal . And I learned this fact in...Wikipedia !