Laravel-mix: [0.12.0] .scripts([input], output) in production environment outputs 'undefined'

Created on 24 May 2017  路  7Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 0.12.0
  • Node Version: 7.5.0
  • NPM Version: 4.1.2
  • OS: OS X El Capitan 10.11.6

Description:

Attempting to minify vanilla JS, without webpack. Running in dev environment works as expected, but production environment outputs 'undefined' for all javascript output files.

Steps To Reproduce:

Using the following files:

package.json

{
  "private": true,
  "scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.15.3",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.3",
    "jquery": "^2.2.3",
    "laravel-mix": "0.*",
    "lodash": "^4.17.4",
    "vue": "^1.0.26"
  }
}

webpack.mix.js
```const { mix } = require('laravel-mix');

mix.options({
processCssUrls: false,
});
mix.sass('resources/assets/sass/app.scss', 'public/css');
mix.scripts(['resources/assets/js/app.js'], 'public/js/app.js');
mix.scripts(['resources/assets/js/enquiry.js'], 'public/js/enquiry.js');
mix.scripts(['resources/assets/js/login.js'], 'public/js/login.js');
mix.scripts(['resources/assets/js/register.js'], 'public/js/register.js');
mix.scripts(['resources/assets/js/search.js'], 'public/js/search.js');
mix.scripts([
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap/collapse.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap/tab.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap/transition.js',
], 'public/js/vendor.js');
mix.copyDirectory('resources/assets/fonts', 'public/fonts');
mix.copyDirectory('resources/assets/img', 'public/img');
```

npm run dev: Outputs all files as expected. Sass, vanilla js (concatenated, unminified), etc.
npm run prod: All js output files contain 'undefined'.

I've downgraded to Laravel Mix 0.11.4, which has fixed my issues.

Most helpful comment

Should be fixed by v0.12.1

All 7 comments

When i debug on this line

I found uglifyjs is throwing errors
DefaultsError: `test` is not a supported option

When I console.log(options.uglify)

 {
  sourceMap: true,
  compress: {
    warnings: false,
    drop_console: true,
    drop_debugger: true,
    angular: false,
    booleans: true,
    cascade: true,
    collapse_vars: true,
    comparisons: true,
    conditionals: true,
    dead_code: true,
    evaluate: true,
    expression: false,
    global_defs: {},
    hoist_funs: true,
    hoist_vars: false,
    if_return: true,
    join_vars: true,
    keep_fargs: true,
    keep_fnames: false,
    keep_infinity: false,
    loops: true,
    negate_iife: true,
    passes: 1,
    properties: true,
    pure_getters: 'strict',
    pure_funcs: null,
    reduce_vars: true,
    screw_ie8: true,
    sequences: true,
    side_effects: true,
    switches: true,
    top_retain: null,
    toplevel: false,
    unsafe: false,
    unsafe_comps: false,
    unsafe_math: false,
    unsafe_proto: false,
    unsafe_regexp: false,
    unused: true
  },
  output: {comments: false},
  test: /\.js($|\?)/i // <== this is the culprit
}

This test property is coming from webpack, because webpack is still using older version of Uglify js.

@JeffreyWay
If UglifyJS has a runtime error should we also show that on terminal and stop building ?

This has also bit me in the butt in recent production pushes as our laravel mix version in package.json is set to 0.* from laravel defaults. It grabbed 0.12 in our recent production pushes and blew up our npm run production output.

Verified that specifying 0.11.4 as laravel mix version has resolved the issue.

@tdondich
npm-shrinkwrap is there to the rescue. No matter you have 0.* in your package.json, npm will always install the one that is specified in npm-shrinkwrap.json.

@ankurk91 so what can i do for resolve? reinstall npm-shrinkwrap? or wait for next release? ty for advance.

@aios
shrink-wrap won't fix this issue but can prevent your CI server from accendently installing unwanted versions.

I would suggest to stick with 0.11.4 , plus specify excat version in package.json .

I found the issue while using .babel, same solution resolved the issue.

Verified setting laravel-mix to 0.11.4 in package.json has it properly uglifying/outputting.

Should be fixed by v0.12.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Micaso picture Micaso  路  3Comments

stefensuhat picture stefensuhat  路  3Comments

mstralka picture mstralka  路  3Comments

sdebacker picture sdebacker  路  3Comments

kpilard picture kpilard  路  3Comments