I came across an issue and found out its because Babel does not polyfill .at as default
According to spec , Array.prototype.at is merely stage 4, and I already set browserslist to > 0.2%, which includes Chrome 86(not supported .at yet)
Why on the earth Babel doest not polyfill .at ?
Hey guys I believe I've fond the reason;
TLDR, the CRA is setting the wrong core-js version config for babel
I'm using create-react-app to build my web app, where I fond polyfill not work properly after installing core-js and import in entry file, according to officail doc;
And the key reason is in
babel-preset-react-app, the babel config which CRA pre-configured and not easily modifiyed by users, have set3for cors-js version; code is hereWhereas, the Babel doc has strongly recommanded to use minor verision , Or :
And in conculsion, no matter what version of corejs we installed, it always use polyfill rule with
3.0version , which would make mistake for some feature polyfills, likeArray.prototype.at;And there is some method to resolve this problem
if u are using pure CRA, u have to do this to import all core-js into your bundle result;
if u work with anything like react-app-rewired or craco, u can achieve this by a more elegant way by correcting the
babel-preset-react-appcode in your node_modules: