question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Laravel mix does not compile import or require statements

See original GitHub issue
  • 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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
fiskhandlarncommented, Aug 24, 2017

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()
      }]
    }]
  }
});
3reactions
WouterFlorijncommented, Aug 24, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel mix does not compile import or require statements
Laravel Mix does not compile import or require . Instead, it simply copies them. It does not perform minification in production mode either,...
Read more >
Laravel mix can not compile import() function - Stack Overflow
You got this import() Unexpected token because missing babel plugin allow parsing of import(). Please try to install one in either:.
Read more >
Laravel Mix - Laravel - The PHP Framework For Web Artisans
In other words, Mix makes it a cinch to compile and minify your application's CSS and JavaScript files. Through simple method chaining, you...
Read more >
CSS Preprocessors | Laravel Mix Documentation
Should you need to compile more than one root file, you may call mix.sass() (or any of the preprocessor variants) as many as...
Read more >
How to compile a set of components into separate files.
Laravel compiles all the components inside App.js, which leaves my file with 400kb. But many components are used in specific areas of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found