JS string.prototype.replaceAll is not a function

Problem description:
In my existing team repls (student assignments) it is not possible to use some modern JS functions like string.replaceAll().

Expected behavior:
const p = ‘The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?’;
console.log(p.replaceAll(‘dog’, ‘monkey’));
// Expected output: “The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?”

Actual behavior:
TypeError: p.replaceAll is not a function
at Object. (/home/runner/06-04JS-strings-040-Maskovac/index.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:999:30)

Steps to reproduce:
Use string.replaceAll() in almost any of my JS assignments

Bug appears at this link:
https://replit.com/@KlIP2Cviceni/06-04JS-strings-040-Maskovac
The link is an assignment for my students in a team. When creating a new repl, inside a team or just a public repl, the code works. However, in my class I have 60+ JS assignments containing asignment descriptions, boilerplate code and multiple unit tests, so re-creating them all again is not an option.

Browser/OS/Device:
Any

looks like the students’ repls are using node.js<15.0. This is probably because they were old and non-nix, and the nix upgrader still kept node.js v12 for compatibility. If there is a replit.nix file (after three dots > show hidden files), change 12_x to 18_x. May be quicker to edit via shell:

sed -i 's/12/18/' replit.nix
1 Like

Thank you. The only hidden file is .upm/store.json.
I made a copy of the repl, tried to execute the command, however it failed:

After, I tried to create an empty replit.nix file and copy inside the contents of a working repl but unluckily, it did not change behaviour anyhow.

1 Like

I would recommend just creating a completely new NodeJS Repl using the current NodeJS Repl template, then copying the code you need into that new Repl.

strange that it isn’t nix upgrading automatically. Maybe a bug with it not happening on education teams. Try adding ?migrateNonNix=1 to the URL of your repl. If that doesn’t work, ig you will just have to move to new node.js repls manually :face_with_diagonal_mouth:

1 Like

Thank you - the migrateNonNix command works, even though I have to manipulate the nix files then to migrate to current Node version. Still, this is much less work than re-creating all my assignments wil all their read.me and test files

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.