rpg maker mv - TypeError: String.prototype.replaceAll called with a non-global RegExp argument

as the title suggests im having a bit of a code issue , i have no idea what the problem is or how to solve it

down below isthe picture of the error codes. i tried looking it up but im gonna be honest coding stuff is way beyond me so im hoping someone who is familiar with this stuff could potentially help if possible :3

the game works A ok completely fine on the rpg maker mv software

but when i deploy it it has this problem after i get to the second map. im thinking it has something to do w me playing around with some of ocrams plugins ? i used the time plugin and the lights plugin together to try and make different things happen at different times of day and it works afaik on my computer just fine? but maybe its somehow getting confused on itchio somehow.

not sure tho tbh. any ideas? thank u so much

Hi there!
I think the problem lies with the RETRO.js plugin.
There is a method for String called "replaceAll" that I believe is not supposed to work on the MV NW.js version.
Maybe the plugin tried to implement that for better support and that lies the problem. Don't know, it is just a guess.
I believe the best way to go is to contact the author of that RETRO plugin, so post that error log on a thread here on the forum(if it has one).
Hi there!
I think the problem lies with the RETRO.js plugin.
There is a method for String called "replaceAll" that I believe is not supposed to work on the MV NW.js version.
Maybe the plugin tried to implement that for better support and that lies the problem. Don't know, it is just a guess.
I believe the best way to go is to contact the author of that RETRO plugin, so post that error log on a thread here on the forum(if it has one).
hii 😀

oh no i was hoping that wasnt the case ;w; ive contacted him twice already for help in such a short span of time i feel so bad bothering him :c ill fiddle with it a bit more n see if any one else is famillar with that issue before messaging him!!! thank u so much for ur help
Ok then!
But next time, I guess is better for you to try to search the plugin thread.
Because even if the author can't help you, you may receive help from other users of the plugin.
Ok then!
But next time, I guess is better for you to try to search the plugin thread.
Because even if the author can't help you, you may receive help from other users of the plugin.
o!!! i had no idea retro wasnt by ocram!!! ill contact the actual maker of retro asap!!! THANK U SO MUCH !!! this was a big help!!!
Hi there!
I think the problem lies with the RETRO.js plugin.
There is a method for String called "replaceAll" that I believe is not supposed to work on the MV NW.js version.
Maybe the plugin tried to implement that for better support and that lies the problem. Don't know, it is just a guess.
I believe the best way to go is to contact the author of that RETRO plugin, so post that error log on a thread here on the forum(if it has one).
Yep that is exactly the case. I have worked with Drakkonis and String.replaceAll is one of the polyfills I have contributed for RETRO.

o!!! i had no idea retro wasnt by ocram!!! ill contact the actual maker of retro asap!!! THANK U SO MUCH !!! this was a big help!!!
Hey no problems and no need to feel bad about contacting me! 🙂

I was thinking that maybe String.replaceAll method is already declared by another plugin? Because polyfill RETRO looks up if it has been already declared...
Code:
if (!''.replaceAll) { // String.replaceAll polyfill
    String.prototype.replaceAll = function (search_string, replace_string) {
        return this.split(search_string).join(replace_string)
    };
};

maybe adding console.log before return would help us to see if polyfill is made by RETRO?
Code:
if (!''.replaceAll) { // String.replaceAll polyfill
    String.prototype.replaceAll = function (search_string, replace_string) {
        console.log("String.replaceAll made by RETRO");
        return this.split(search_string).join(replace_string)
    };
};

Another thing that came to mind is that maybe regex in split isn't allowed in MV NW version...

You can try to run this in console.
Code:
'abc123'.split(/[a]/).join("X");
Yep that is exactly the case. I have worked with Drakkonis and String.replaceAll is one of the polyfills I have contributed for RETRO.


Hey no problems and no need to feel bad about contacting me! 🙂

I was thinking that maybe String.replaceAll method is already declared by another plugin? Because polyfill RETRO looks up if it has been already declared...
Code:
if (!''.replaceAll) { // String.replaceAll polyfill
    String.prototype.replaceAll = function (search_string, replace_string) {
        return this.split(search_string).join(replace_string)
    };
};

maybe adding console.log before return would help us to see if polyfill is made by RETRO?
Code:
if (!''.replaceAll) { // String.replaceAll polyfill
    String.prototype.replaceAll = function (search_string, replace_string) {
        console.log("String.replaceAll made by RETRO");
        return this.split(search_string).join(replace_string)
    };
};

Another thing that came to mind is that maybe regex in split isn't allowed in MV NW version...

You can try to run this in console.
Code:
'abc123'.split(/[a]/).join("X");
hi ocram <3 im sorry i keep pestering u but ur just so helpful and nice hehe

i had to look up how to do the console and i thiiiink i did it right? i hit f12 on deployment on itchio and then copy pasted those codes in the little box i could type in under the error codes ? if thats right 🙂

as u can see the first two came up undefined and the last one came up with something and i have 0 clue on what that means or how to fix it lol



Don't worry about those "undefined"s, that just means the code you entered didn't return a value (which it shouldn't, since an if statement isn't a function that returns a value even if the block itself has a return statement in it; the return value is there, but not being used or received by anything).

The result of the split just means that the nw version does support split, so the polyfill should work.

What Ocram was suggesting was adding that console.log to the code of the RETRO plugin, not running it in the console. Then when replaceAll is called, you'll see that message in the console if the function is coming from there and not somewhere else.
hi ocram <3 im sorry i keep pestering u but ur just so helpful and nice hehe

i had to look up how to do the console and i thiiiink i did it right? i hit f12 on deployment on itchio and then copy pasted those codes in the little box i could type in under the error codes ? if thats right 🙂

as u can see the first two came up undefined and the last one came up with something and i have 0 clue on what that means or how to fix it lol




First find row String.prototype.replaceAll = function (search_string, replace_string) { ... in RETRO.js (located in ./js/plugins -folder).

Then replace that row with this code:
Code:
String.prototype.replaceAll = function (search_string, replace_string) {
    console.log("String.replaceAll made by RETRO");
    return this.split(search_string).join(replace_string)
};
(save changes >> deploy (make sure retro.js isn't loaded from cache).

Then you can check console log if that polyfill is used for String.replaceAll

If "String.replaceAll made by RETRO" won't appear in log it means something is overriding that method. You can test it by writing to console with following script:
Code:
'abanta-123'.replaceAll('a', 'u');
First find row String.prototype.replaceAll = function (search_string, replace_string) { ... in RETRO.js (located in ./js/plugins -folder).

Then replace that row with this code:
Code:
String.prototype.replaceAll = function (search_string, replace_string) {
    console.log("String.replaceAll made by RETRO");
    return this.split(search_string).join(replace_string)
};
(save changes >> deploy (make sure retro.js isn't loaded from cache).

Then you can check console log if that polyfill is used for String.replaceAll

If "String.replaceAll made by RETRO" won't appear in log it means something is overriding that method. You can test it by writing to console with following script:
Code:
'abanta-123'.replaceAll('a', 'u');
i think i did it right this time? i edited the js file in text document and found the first thing and replaced all of it with the second thing, and it turned off all of ur plugins i think ? cos they werent working when i play tested it :0

just tested it on deployment and it works great except the same as above ur plugins arent there :0 im excited we are in the right direction though

heres the new problems. again 0 clue a little above this it was saying Uncaught TypeError: PluginManager.registerCommand is not a function for your plugins

i think i did it right this time? i edited the js file in text document and found the first thing and replaced all of it with the second thing, and it turned off all of ur plugins i think ? cos they werent working when i play tested it :0

just tested it on deployment and it works great except the same as above ur plugins arent there :0 im excited we are in the right direction though

heres the new problems. again 0 clue a little above this it was saying Uncaught TypeError: PluginManager.registerCommand is not a function for your plugins


Ok I PM'ed whole RETRO.js to you with edits made.
As far as I can tell, it's not because the function is bad, rather how RETRO uses it. In version 0.10, it parses plugin command arguments by using the replaceAll function, passing a Regex as an argument. But at some point there was an update to... I think JS itself? The node? Either way, it doesn't like the Regex argument being passed without the global tag. I THINK the problem largely comes from setups where the function we're filling in already exists, and so the native issue with non-global regex pops up. But don't quote me on that, that's a guess with the information I have available.

Version 0.11 changes that call to use a simple string, which it shouldn't have a problem with.

This is the downside to all RETRO development being done in testing environments. I have no idea how any differences in a deployed version of a game will affect things, since I have no such deployments. But it does kinda fit in with RETRO's development style of stuff being done because other stuff breaks. lol

Original thread: https://forums.rpgmakerweb.com/threads/rpg-maker-mv-typeerror-string-prototype-replaceall-called-with-a-non-global-regexp-argument.146831/