create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

react-app-polyfill does not polyfill String.prototype.replaceAll

Open tanukihee opened this issue 3 years ago • 3 comments

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

  1. run npx create-react-app test --template typescript
  2. Add import "react-app-polyfill/stable"; to the first line of src/index.tsx
  3. Add "chorme > 80" to browserlists.production of package.json
  4. Change the App.tsx file to
function App() {
  return <>{"app".replaceAll("a", "A")}</>;
}

export default App;
  1. run npm start

Expected behavior

image

It displays "App". Screenshotted from Edge 104

Actual behavior

image

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

Reproducible demo

test.zip

Others

I found the same question at stackoverflow and it seems to be an old bug that has not yet been fixed

tanukihee avatar Aug 31 '22 04:08 tanukihee

Same error occured in my production build,Please fix!

istobran avatar Nov 23 '22 06:11 istobran

Is there any fix for that ?

AdamK222 avatar Jan 30 '23 11:01 AdamK222

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, '_');

cristian-atehortua avatar Mar 19 '24 17:03 cristian-atehortua