This most likely happens because String.prototype.replaceAll is not implemented in Node.js (at least as of version v14.15.0).
One alternative you could use are regular expressions like in this example:
const str="foo-foo";
const regex = /foo/g; // Note the 'g' flag, which matches all occurrences of the expression
console.log(str.replace(regex, 'bar')); // 'bar-bar'
You can check here for more info on regular expressions.