Skip to content
Advertisement

Webpack – package: @babel/polyfill has been deprecated – How to use an alternative?

I came back to my Webpack 4 configuration and all the packages after 4 months. It always surprises me how fast a package get’s updated or deprecated.

I have this problem, that I used to include the @babel/polyfill directly to the Webpack’s entry => src together with my other JS and SASS source.

This is my current .babelrc file:

JavaScript

And my Webpack’s entry setting:

JavaScript

And the config where i setup all the exports:

JavaScript

My package.json with the Babel files:

JavaScript

Is there any replacement that i can use for the @babel/polyfill as of today?

I would like to keep a polyfill but replace it with the deprecated package.

Thanks!

EDIT:

JS file causing an error for some reason Arrow functions are not working in production mode only:

JavaScript

Webpack file:

JavaScript

Advertisement

Answer

core-js is currently replacing bable-polyfill. You do not have to set it anywhere except for the .babelrc file I have a question, why do you duplicate libraries you have @babel/polyfill and babel-pollyfill the same applies to @babel/preset-env and babel-preset-en. You have declared in .babelrc corejs but I do not see that package.json has been installed?

My example may not be perfect but I try to strive for it 🙂

.babelrc

JavaScript

package.json

JavaScript

webpack.config.js

JavaScript

index.js

JavaScript

UPDATE

add to package.json, you can prepare your own list of supported browsers

JavaScript

add to .babelrc

JavaScript

After all these additional changes in the console will appear what browsers are supported and what pollyfill have been added. And of course the most important thing is to test it in IE11. I always test on 6-7 desktop and 3-4 mobile browsers.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement