This is impossible in general. Indeed, if $X$ has a compact support, then the flux of $X$ through a large enough sphere is $0$, whereas the integral of $f$ over the corresponding ball (say $B$) will not be $0$ if e.g. the restriction of $f$ to $B$ is a nonnegative nonzero function, so that the integral of $f$ over $B$ be nonzero. So, if $\text{div}\,X=f$, we get a contradiction with the [divergence theorem][1]. [1]: https://en.wikipedia.org/wiki/Divergence_theorem#Mathematical_statement