scottcharlesworth / laravel-mix-polyfill

A Laravel Mix extension to include polyfills by using Babel, core-js, and regenerator-runtime
MIT License
50 stars 7 forks source link

Using `debug: true` throws BABEL_UNKNOWN_OPTION #36

Closed elambro closed 3 years ago

elambro commented 3 years ago

Thanks for the package!

When adding debug: true to the options, I receive the following error in webpack:

[webpack-cli] Error: Unknown option: .cacheDirectory. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options. at throwUnknownError (/var/www/dev/dev.local/node_modules/laravel-mix/node_modules/@babel/core/lib/config/validation/options.js:135:27) at /var/www/dev/dev.local/node_modules/laravel-mix/node_modules/@babel/core/lib/config/validation/options.js:120:5 at Array.forEach (<anonymous>) at validateNested (/var/www/dev/dev.local/node_modules/laravel-mix/node_modules/@babel/core/lib/config/validation/options.js:96:21) at validate (/var/www/dev/dev.local/node_modules/laravel-mix/node_modules/@babel/core/lib/config/validation/options.js:87:10) at loadPrivatePartialConfig (/var/www/dev/dev.local/node_modules/laravel-mix/node_modules/@babel/core/lib/config/partial.js:64:50) at loadPrivatePartialConfig.next (<anonymous>) at Function.<anonymous> (/var/www/dev/dev.local/node_modules/laravel-mix/node_modules/@babel/core/lib/config/partial.js:131:25) at Generator.next (<anonymous>) at evaluateSync (/var/www/dev/dev.local/node_modules/gensync/index.js:251:28) { code: 'BABEL_UNKNOWN_OPTION' }

Usage:

require('laravel-mix-polyfill');
mix.polyfill({
    corejs     : "3.12",
    enabled    : true,
    useBuiltIns: "usage",
    targets    : "> 0.25%, IE 11, not dead",
    // debug      : true
});
scottcharlesworth commented 3 years ago

@elambro

Can you try:

require('laravel-mix-polyfill');
mix.polyfill({
    corejs: 3,
    enabled: true,
    useBuiltIns: "usage",
    targets: "> 0.25%, IE 11, not dead",
    debug: true
});
elambro commented 3 years ago

Yep, I get the exact same error.

scottcharlesworth commented 3 years ago

Okay.

So what should happen, and used to happen, is that the cacheDirectory property is changed to false in the object returned from the babelConfig() function and overwrites the default value supplied by Mix.

For some reason now it does not work and Babel spits it out.

Whilst I investigate, you can add the following to your chain to do the same as debug: true:

mix.override(webpackConfig => {
    let javascriptIndex = null;

    webpackConfig.module.rules.forEach(function (value, index) {
        if (value['test'].toString() === '/\\.(cjs|mjs|jsx?|tsx?)$/') {
            javascriptIndex = index;
        }
    });

    if (javascriptIndex) {
        webpackConfig.module.rules[javascriptIndex]['use'][0]['options']['cacheDirectory'] = false;
        webpackConfig.module.rules[javascriptIndex]['use'][0]['options']['presets'][0]['options']['debug'] = true;
    }
});
scottcharlesworth commented 3 years ago

For reference, it was a change in Laravel Mix v6.0.14 that caused this to break.

scottcharlesworth commented 3 years ago

Fixed in v3.0.1