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 & Vue : Module parse failed: Unexpected token

See original GitHub issue

Hi I want to use Vue 2 with laravel mix 6 but it didn’t work it display this error message :

Module parse failed: Unexpected token

webpack.mix.js

const mix = require(‘laravel-mix’);

mix.js('resources/js/app.js', 'js')
   .vue({ version: 2 })
   .setPublicPath('public');
   
if (mix.inProduction()) {
    mix.version();
} 

package.json

"devDependencies": {
 ......
"laravel-mix": "^6.0.6",
"vue": "^2.6.12",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12"
 }

resources/js/app.js

require('./bootstrap');

import Vue from 'vue';
import App from './components/App.vue';

new Vue({
    el: '#app',
    components: { App }
});

resources/js/components/App.vue

<template>
    <div class="alert" v-text="message"></div>
</template>

<script>
export default {
    data() {
        return {
            message: 'I am an alert.'
        };
    }
};
</script>

<style>

</style




Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:19

github_iconTop GitHub Comments

81reactions
5baddicommented, Jan 24, 2021

Just add .vue({ version: 2 }) in webpack.mix.js mix.js('resources/js/app.js', 'public/js').vue({ version: 2 });

34reactions
brachyceracommented, Jan 21, 2021

I had similar problems upgrading Laravel-Mix.

package.json

   "laravel-mix": "^6.0.10",
   "vue-loader": "^15.9.6",
   "vue-template-compiler": "^2.6.12",
   "vue": "^2.6.12"

webpack.mix.js

mix.js('resources/js/app.js', 'public/js').vue({ version: 2 });

app.js

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

For me the information from this answer https://github.com/JeffreyWay/laravel-mix/issues/2747#issuecomment-755483920 fixed my problem

…import Vue as an ES6 module, or to add .default after the require…

Also the upgrade guide had some useful information - https://github.com/JeffreyWay/laravel-mix/blob/master/UPGRADE.md

Hope this might help :bowtie:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Mix & Vue : Module parse failed: Unexpected token
Hi I want to use Vue 2 with laravel mix 6 but it didn't work it display this error message : Module parse...
Read more >
Laravel Mix & Vue : Module parse failed ... - Laracasts
Hi I want to use Vue 2 with laravel mix 6 but it didn't work it display this error message : Module parse...
Read more >
Laravel Mix Module parse failed: Unexpected token (18:20)
My problem solved. In my case, original error comes from vue part. In vue router index.js file there was 'import { vue }...
Read more >
Laravel Mix & Vue : Module parse failed: Unexpected token
I was trying to use Vue with Laravel 8 while running running npm run dev, encountered following error. package.json ...
Read more >
Now I got the below error while using Vue in the laravel ...
Now I got the below error while using Vue in the laravel project. Uncaught Error: Module parse failed: Unexpected token (1:0)
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