0

The .replaceAll methods fail with; String.replaceAll is not a function with Quokka, how can that be?

const userName = 'Speedster1000';
const greeting = 'Welcome back user';
const text = 'When user wins the game, then user will earn a reward!';

// .replace(search, replace)
console.log(greeting.replace('user', userName));

// .replaceAll(search, replace)
console.log(text.replaceAll('user', userName));

Solution: You need to have the latest version of Node.js because Quokka runs with Node.js. Since the old version of Node.js does not support .replaceAll.

  • 1
    [`replaceAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) is a relatively new addition to JavaScript's standard library. If you're getting that error, it's because the environment where you're running this doesn't have it (yet). See the [linked question's answers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) for how to replace all occurrences with `replace` (TL;DR: `.replace(/user/g, userName)`.) – T.J. Crowder Aug 20 '21 at 08:36

0 Answers0