Laravel-mix: Can't disable Terser in production mode

Created on 16 Jan 2019  路  6Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 4.0.13
  • Node Version: 11.6.0
  • Yarn Version: 1.13.0
  • OS: Ubuntu 18.04 Vagrant box on a Windows 7 host

Description:

While running in production mode, if terser is set to false an error is thrown.

Simplest Reproducible webpack.mix.js:

require('laravel-mix')
    .options({ terser: false })
    .js('resources/assets/js/app.js', 'public/js');

Steps To Reproduce:

  • Use the above webpack.mix.js file
  • yarn build -p

Error:

ubuntu@ubuntu-bionic:/var/www/xxxx$ yarn build -p
yarn run v1.13.0
$ node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js -p
Terser Plugin Invalid Options

options should be object

ValidationError: Terser Plugin Invalid Options
    at validateOptions (/vagrant/node_modules/schema-utils/src/validateOptions.js:32:11)
    at new TerserPlugin (/vagrant/node_modules/terser-webpack-plugin/dist/index.js:40:30)
    at module.exports (/vagrant/node_modules/laravel-mix/src/builder/webpack-default.js:41:23)
    at new WebpackConfig (/vagrant/node_modules/laravel-mix/src/builder/WebpackConfig.js:14:30)
    at Object.<anonymous> (/vagrant/node_modules/laravel-mix/setup/webpack.config.js:29:18)
    at Module._compile (/vagrant/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:657:17)
    at require (/vagrant/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
stale

Most helpful comment

Did you try this?

terser: {
            terserOptions: {
                compress: false
            }
        }

also, maybe mix.sourceMaps() will help you?

All 6 comments

Also worth noting that you can't enable it in development mode either.

Why would someone wants to disable to js minification in production?

I personally ran into this situation trying to debug a problem that only occurred while compiling for production. It would have been very helpful to be able to disable terser to narrow down what could be causing the issue, so I had to manually modify the laravel-mix source files temporarily.

That being said, I'm sure there are other cases where one would want to disable it in production - maybe in a case where sourcemaps aren't working 100% and you need a more helpful error log.

Did you try this?

terser: {
            terserOptions: {
                compress: false
            }
        }

also, maybe mix.sourceMaps() will help you?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

You can disable minification in Laravel Mix like so:

mix.webpackConfig({
    optimization: {
        minimize: false,
    }
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bomavi picture Bomavi  路  3Comments

sdebacker picture sdebacker  路  3Comments

jpriceonline picture jpriceonline  路  3Comments

pixieaka picture pixieaka  路  3Comments

terion-name picture terion-name  路  3Comments