Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

warpig's avatar
Level 12

Installing Vue through Laravel Mix is hard

Well it's not as how it is written in the documentation or perhaps im not fully understanding it. Created a fresh project and did everything that said and I get errors. This is what the documentation says:

  1. Ensure NodeJs and NPM are both installed on your machine. While being at the user root level on my machine, (not in the projects folder) I ran npm -v and node -v and both of them were installed. Good.
  2. Then on the project folder level, run npm install this installs all npm dependencies, since I want Vue, and it is a Javascript front-end framework, it needs to have these, it's like what it runs on, like Laravel needs Composer.

Besides installing Vue I also want TailwindCSS, that gave me no problem, at the end the Laravel Mix app built the application.

For installing Tailwind, as per the documentation: https://laravel.com/docs/8.x/mix#tailwindcss

After that was done, and given the information on the documentation I continued reading down and https://laravel.com/docs/8.x/mix#working-with-scripts now we get to the part for Vue and other frameworks.

  1. You need to add .vue() inside a file named webpack.mix.js below this line: mix.js('resources/js/app.js', 'public/js'), done!
  2. Apparently that's all one needs regarding the documentation, again I wanted to base my installation solely on what it's written in there, I believe it's the best approach.
  3. npm run dev threw a bunch of errors, one line in particular stood out: We couldn't find a supported version of Vue in your project. Please ensure that it's installed (npm install vue).

Ok, so I need to install vue through npm. Ran it, but again I encounter some other issues. Conclusion; not only am I not getting Vue but also there seemed to be a problem with Valet. Perhaps my knowledge of how my dev environment needs to be set is wrong, I mean should my dev environment be in a certain way? It was clear enough that I only needed Node and NPM before actually trying to do anything with Mix. Sometimes I don't get these CLI procedures, could somebody please tell me what's wrong here?

Nevertheless there is yet another method which im familiar with for getting Vue, and that is through composer require laravel/ui and php artisan ui vue but I don't want any extra files, I wish to make my UI layouts and components using TailwindCSS or CSS. Thanks! I need to know how to get Vue so I can be familiar with a process that actually works it is why im making this loong post, but I never expected I would be mislead. Again, thank you for your patience! :-)

0 likes
18 replies
tykus's avatar

Can you share your actual webpack.mix.js and resources/js/app.js files?

1 like
warpig's avatar
Level 12

I have to tell you, I recreated another Laravel project but still experiencing the same results/problems.

webpack.mix.js

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', [
        require('tailwindcss'),
    ]);

resources/js/app.js

require('./bootstrap');
tykus's avatar

You don't require orimport Vue.

// resources/js/app.js

require('./bootstrap');
import Vue from 'vue';

new Vue({
	// ...etc
});

This shouldn't cause a failure of npm though. Whenever you run npm run dev for the first time after changing the webpack.mix.js file, does Mix install additional dependencies? You need to run npm run dev again after this setup step.

warpig's avatar
Level 12

Whenever you run npm run dev for the first time after changing the webpack.mix.js file, does Mix install additional dependencies?

Maybe that's why but no it doesn't install dependencies. However if you go back to the initial post, point 2, I ran npm install if that's what you mean. The code you provided is not building or importing Vue. I get a Laravel Mix error.

ERROR in ./resources/js/app.js 4:0-22
Module not found: Error: Can't resolve 'vue' in '/Users/eduardocoello/Projects/vuecomps/resources/js'

webpack compiled with 1 error
sr57's avatar

@warpig

Why don't you use breeze or jetstream with inertia?

1 like
warpig's avatar
Level 12

At one point or another authentication is needed when you have a backend, I get that.. but at this point im not trying to install any of that, if it were up to me I would rather learn how to install Vue separately, though I know, at least for Breeze, you need to install it from the get-go, wouldn't want to lose any code. And I don't know about Jetstream or Inertia but Vue is a framework widely used and Inertia is brand new (I think) so I would rather also learn Vue first.

sr57's avatar

@warpig

Ok, your are just a little bit behind me :-)

~1 month ago, I succeeded to install vue3 with this cde, and when I saw it was working (ie witouh learning Vue) I decided to go via Inertia.

npm i -D laravel-mix@next vue@next @vue/compiler-sfc vue-loader@next

warpig's avatar
Level 12

You ran that from a fresh installation of Laravel? Doesn't seem to work, yes I can run it and it will install something but I don't get the components folder under resources/js + if I try to import and initialize Vue Im still getting an error.

sr57's avatar

@warpig

Yes from a fresh Laravel install.

You haven't forget to run : npm install ; npm run dev

Not 100% sure, but I think that components folder is not auto created, you have to create it.

Find my webpack.mix.js et package.json to compare with yours.

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()
{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "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 --disable-host-check --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 --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@vue/compiler-sfc": "^3.0.4",
        "axios": "^0.19",
        "cross-env": "^7.0",
        "laravel-mix": "^6.0.0-beta.17",
        "lodash": "^4.17.19",
        "postcss": "^8.2.1",
        "resolve-url-loader": "^3.1.0",
        "vue": "^3.0.4",
        "vue-loader": "^16.1.1"
    },
}
1 like
warpig's avatar
Level 12

Yes it is the same. After running that command I think that did that but why would the build fail if I try to import vue? that's just odd, it should've worked by now :-/

P-James's avatar

Man I hate config and am no expert but the only thing I can think is you might have one of either:

an incompatible version of node

an incompatible combination of Vue and Mix (eg, I'm not 100% sure if Vue 3 works with Mix).

You might get more help if you post your package.json and composer.json

warpig's avatar
Level 12

Hello @perdanjam, I have shared both of those, check the reply I wrote to @tykus if it's about compatibility, do you know where I can check for that? EDIT: I never replied those files so here you go, sorry for the mix-up! Lol

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "axios": "^0.21",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14",
        "tailwindcss": "^2.0.3"
    }
}

composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.12",
        "laravel/tinker": "^2.5"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}
P-James's avatar

@warpig I think you may have installed Vue in a different folder..? It's not in your package.json devDependencies. Have a look to see if you have a node_modules somewhere other than your root directory.

Delete that and navigate to your route use cd .. to go up a level in your terminal and reinstall vue

warpig's avatar
Level 12

It's still unclear to me when did I actually "installed" or came close to even installing Vue, was it when I ran the npm install command? Or when I added it to the webpack file? When I did that I then ran npm run dev and that's when it started to fail. The node_modules folder exists in the app and in no other folder elsewhere :-(

warpig's avatar
warpig
OP
Best Answer
Level 12

A couple of things to consider then, and it's still a mystery as to why it wouldn't be in the docs but like I said it could be just me that im not aware of other things, it also may be that previous work with Vue is required, who knows.

Where I felt like I was misleaded, regarding the documentation instructions was that after doing everything up to this point: https://laravel.com/docs/8.x/mix#vue, you still need to install Vue through NPM: (https://vuejs.org/v2/guide/installation.html#NPM) and after that, you can certainly start using Vue.

app.js

import Vue from 'vue';
window.Vue = require('vue');

new Vue({
    el: '#app',
});
1 like
P-James's avatar

Mix is a wrapper around Webpack. Its main purpose is to bundle code that you already have (usually this means making a single browser-friendly app.js file from many different .js/.vue /.whatever files).

In your case, Vue wasn't installed, so the .vue() method in Mix caused an error.

Programador Vagabundo's avatar

@warpig @warpig I think the easiest method to get Vue in Laravel is as explained in Laravel 7 [laravel(dot)com/docs/7.x/frontend#introduction] since this method is still valid in Laravel 9 we just have to change the version to a more current one for example:

composer require laravel/ui:^3.4

and then follow the steps described in [laravel(dot)com/docs/7.x/frontend#introduction] or in [packagist(dot)org/packages/laravel/ui] as you prefer, for example:

php artisan ui vue

later:

npm install

and finally:

npm run dev

tec's avatar

This worked for me:

I realised that mix was trying to run a lower version of vue (version 2) yet I had vue 3 installed. So I specified the version to match the version installed on my machine in the webpack.mix.js like so:

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', []).vue({ version: 3 });
1 like

Please or to participate in this conversation.