Laravel Mix Transpile Node Modules

raw JSON →
2.0.4 verified Sat Apr 25 auth: no javascript

Laravel Mix extension for transpiling JavaScript dependencies inside node_modules with Babel. Current stable version is 2.0.4, compatible with Mix v4, v5, and v6. It selectively applies Babel transformations to problematic npm packages that fail to compile under the default webpack `exclude` rule for node_modules. Differentiator: no manual webpack config needed — simply call `mix.transpileNodeModules()` in your `webpack.mix.js` file. Actively maintained, latest updates fix Windows path issues and babel-loader detection.

error Error: Cannot find module 'laravel-mix-transpile-node-modules'
cause Package not installed or missing from package.json.
fix
Run: npm install laravel-mix-transpile-node-modules --save-dev
error TypeError: mix.transpileNodeModules is not a function
cause require('laravel-mix-transpile-node-modules') not called before usage.
fix
Add require('laravel-mix-transpile-node-modules') at the top of your webpack.mix.js.
error Error: No babel-loader found. Make sure babel-loader is installed.
cause babel-loader is not installed in the project.
fix
Install babel-loader: npm install babel-loader --save-dev
gotcha Previously, babel-loader detection failed on Windows due to path separator mismatch. Fixed in v2.0.3.
fix Update to v2.0.3+.
gotcha Empty webpack rule tests caused errors. Fixed in v2.0.4.
fix Update to v2.0.4+.
breaking Version 2.0.0 dropped support for Mix v3. Only v4, v5, and v6 are supported.
fix Upgrade Laravel Mix to v4+ or stay on v1.x of this package.
gotcha Transpiling all node_modules can significantly increase build times. Use selective transpilation with array of module names when possible.
fix Pass only the problematic packages: mix.transpileNodeModules(['swiper', 'dom7']).
gotcha Calling mix.transpileNodeModules() in development may cause performance issues if many modules are transpiled.
fix Wrap the call in a production check: if (mix.inProduction()) { mix.transpileNodeModules() }.
npm install laravel-mix-transpile-node-modules
yarn add laravel-mix-transpile-node-modules
pnpm add laravel-mix-transpile-node-modules

Registers the extension and conditionally transpiles all node_modules in production builds.

// webpack.mix.js
const mix = require('laravel-mix');
require('laravel-mix-transpile-node-modules');

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

if (mix.inProduction()) {
  mix.transpileNodeModules();
}