Laravel-mix: Laravel mix does not compile import or require statements

Created on 24 Aug 2017  路  5Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.4.2
  • Node Version: 6.11.2
  • NPM Version: 3.10.10
  • OS: Windows 10

Issue

Laravel Mix does not compile import or require. Instead, it simply copies them.

It does not perform minification in production mode either, but that's a side-issue.

Steps to reproduce

  1. Create a new npm project.
  2. Install laravel-mix through npm and copy the scripts to your package.json.
  3. npm install some package.
  4. Create app.js:
import package from 'package'; // Or package = require('package');
  1. Add mix.babel('inputpath/app.js', 'outputpath/app.js'); to your webpack.mix.js.
  2. Run npm run dev or any other compilation script.

The output file will just be the same as the input file. Meanwhile, other ES6 features _are_ compiled correctly (tested with classes and arrow syntax for example).

Am I missing something, or is this a bug?

Most helpful comment

Same thing happens to me. I found a workaround here. Don't know if it affects performance though.

mix.js('resources/assets/js/app.js', 'public/js');

mix.webpackConfig({
  module: {
    rules: [{
      test: /\.js?$/,
      use: [{
        loader: 'babel-loader',
        options: mix.config.babel()
      }]
    }]
  }
});

All 5 comments

Same thing happens to me. I found a workaround here. Don't know if it affects performance though.

mix.js('resources/assets/js/app.js', 'public/js');

mix.webpackConfig({
  module: {
    rules: [{
      test: /\.js?$/,
      use: [{
        loader: 'babel-loader',
        options: mix.config.babel()
      }]
    }]
  }
});

@fiskhandlarn Thanks! That works for now. However, it seems like using mix.babel should just work.

For me, using mix.js without the config you mentioned works in development mode, but crashes in production mode (during minification). With the config, it also works in production.

@WouterFlorijn I agree, that would have been the best/easiest. :)

If the package you're requiring was written in es6, it won't be compiled down. You'd need to require the compiled version of that package.

@JeffreyWay The package I'm trying to require is my own written ES6 code for the app/site. It would be nice to be able to compile that with mix.babel. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpilard picture kpilard  路  3Comments

rlewkowicz picture rlewkowicz  路  3Comments

nezaboravi picture nezaboravi  路  3Comments

pixieaka picture pixieaka  路  3Comments

Cheddam picture Cheddam  路  3Comments