create-react-app
create-react-app copied to clipboard
react-app-polyfill does not polyfill String.prototype.replaceAll
Describe the bug
react-app-polyfill does not polyfill String.prototype.replaceAll.
Environment
Environment Info:
current version of create-react-app: 5.0.1
running from C:\Users\listl\scoop\persist\nodejs\cache\_npx\c67e74de0542c87c\node_modules\create-react-app
System:
OS: Windows 10 10.0.19044
CPU: (16) x64 AMD Ryzen 7 PRO 4750U with Radeon Graphics
Binaries:
Node: 18.8.0 - ~\scoop\apps\nodejs\current\node.EXE
Yarn: Not Found
npm: 8.18.0 - ~\scoop\apps\nodejs\current\npm.CMD
Browsers:
Chrome: 81.0.4044.92
Edge: Spartan (44.19041.1266.0), Chromium (104.0.1293.70)
Internet Explorer: 11.0.19041.1566
npmPackages:
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
react-scripts: 5.0.1 => 5.0.1
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
- run
npx create-react-app test --template typescript - Add
import "react-app-polyfill/stable";to the first line ofsrc/index.tsx - Add
"chorme > 80"tobrowserlists.productionofpackage.json - Change the App.tsx file to
function App() {
return <>{"app".replaceAll("a", "A")}</>;
}
export default App;
- run
npm start
Expected behavior

It displays "App". Screenshotted from Edge 104
Actual behavior

"app".replaceAll is not a function. Screenshotted from Chrome 81, for Chrome started supporting String.prototype.replaceAll from 85

Reproducible demo
Others
I found the same question at stackoverflow and it seems to be an old bug that has not yet been fixed
Same error occured in my production build,Please fix!
Is there any fix for that ?
Create React App is deprecated and it will not be updated anymore. Migrate to vite and use String.prototype.replace with RegEx with the g flag:
- myStr.replaceAll('-', '_');
+ myStr.replace(/-/g, '_');