How to fix the error "You may need an appropriate loader to handle this file type" How to fix the error "You may need an appropriate loader to handle this file type" vue.js vue.js

How to fix the error "You may need an appropriate loader to handle this file type"


as your using laravel-mix 6 it have different config for webpack.mix.js

webpack.mix.js

use .vue()

const mix = require('laravel-mix');/* |-------------------------------------------------------------------------- | Mix Asset Management |-------------------------------------------------------------------------- | | Mix provides a clean, fluent API for defining some Webpack build steps | for your Laravel applications. By default, we are compiling the CSS | file for the application as well as bundling up all the JS files. | */mix.js('resources/js/app.js', 'public/js').vue()    .postCss('resources/css/app.css', 'public/css', [        //    ]);

ref link https://laravel-mix.com/docs/6.0/upgrade


If anyone still encounters this issue, here how I figure out the cause in my case and it's actually a Laravel mix 6 configuration issue for Vue support.

You can check the documentation for more details : Laravel mix 6 upgrade documentation

But let me explain it in short here...

I was using Laravel mix 6 (you may probably use the same if you created a fresh Laravel 8 project) and according to its official documentation "Laravel Mix 6 ships with support for the latest versions of numerous dependencies, including webpack 5, PostCSS 8, Vue Loader 16, and more". So no need for you to add vue loader although the error states it.

You rather need to tell explicitly Laravel mix 6 to support vue, here what they say "Laravel Mix was originally built to be quite opinionated. One of these opinions was that Vue support should be provided out of the box. Any call to mix.js() would instantly come with the benefit of Vue single-file components.

Though we're not removing Vue support by any stretch, we have extracted Vue to its own "featured flag": mix.vue().

Here what I did.

First option

// You can simply use thismix.js('resources/js/app.js', 'public/js').vue().postCss('resources/css/app.css', 'public/css', [        //]);

Second option

// Or this if you want to extract styles as well// Feel free to check the documentation for more customisationsmix.js('resources/js/app.js', 'public/js').vue({    extractStyles: true,    globalStyles: false}).postCss('resources/css/app.css', 'public/css', [        //]);


First of all, thanks to Paul for this clarification which saved my evening :)

After that the compilation worked for me, but an error appeared in the console when I reloaded the page:

Vue.use is not a function

For those who would be in the same case, in your app.js file, you must replace the line :

window.Vue = require('vue');

With :

window.Vue = require('vue').default;