laravel-mix-polyfill
raw JSON → 3.0.1 verified Sat Apr 25 auth: no javascript
A Laravel Mix extension that integrates Babel, core-js, and regenerator-runtime to include polyfills in your Mix build. Version 3.0.1 is the latest stable release, compatible with Laravel Mix v6 and Webpack v5. It replaced the deprecated @babel/polyfill with core-js and regenerator-runtime in v2.0.0, and fixed a debug option error in v3.0.1. Compared to manual Babel configuration, this extension provides a simple Mix-friendly API for polyfill targeting via browserslist queries.
Common errors
error TypeError: mix.polyfill is not a function ↓
cause The require('laravel-mix-polyfill') is missing or placed after calling mix.polyfill().
fix
Add require('laravel-mix-polyfill') at the top of webpack.mix.js before using mix.polyfill().
error Error: Cannot find module 'laravel-mix-polyfill' ↓
cause Package not installed or not in node_modules.
fix
Run npm install laravel-mix-polyfill --save-dev
error Error: Polyfill target 'firefox 50' is not a valid browserslist query ↓
cause Invalid or malformed browserslist string in the targets option.
fix
Use a valid browserslist query like '> 0.25%, not dead' or ensure correct syntax.
Warnings
breaking v3.0.0 drops support for Laravel Mix v5 and earlier; requires Laravel Mix v6+ and Webpack v5. ↓
fix Upgrade to Laravel Mix v6+ and Webpack v5.
breaking v2.0.0 removes @babel/polyfill in favor of core-js and regenerator-runtime. If you imported core-js entries manually, they may conflict. ↓
fix Remove any manual @babel/polyfill imports; let the extension handle polyfill entries.
deprecated Setting useBuiltIns: 'entry' is deprecated in core-js@3; consider using 'usage' for automatic per-file polyfilling. ↓
fix Change useBuiltIns to 'usage' and let Babel inject only needed polyfills.
gotcha Mixing .polyfill() with other polyfill plugins (e.g., @babel/preset-env polyfill options) can cause duplicate or missing polyfills. ↓
fix Avoid configuring polyfills elsewhere in Babel config; rely solely on this extension.
gotcha Setting debug: true with Laravel Mix v6.0.14+ and this extension v3.0.0 caused an error; fixed in v3.0.1. ↓
fix Update to v3.0.1 or later.
Install
npm install laravel-mix-polyfill yarn add laravel-mix-polyfill pnpm add laravel-mix-polyfill Imports
- require('laravel-mix-polyfill') wrong
import 'laravel-mix-polyfill';correctrequire('laravel-mix-polyfill'); - mix.polyfill() wrong
mix.polyfill({ enabled: true }).js('src', 'dest');correctmix.js('src', 'dest').polyfill({ enabled: true });
Quickstart
// webpack.mix.js
let mix = require('laravel-mix');
require('laravel-mix-polyfill');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.polyfill({
enabled: true,
useBuiltIns: 'usage',
targets: 'firefox 50, IE 11'
});