laravel-mix: 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 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 19
Just add
.vue({ version: 2 })in webpack.mix.jsmix.js('resources/js/app.js', 'public/js').vue({ version: 2 });I had similar problems upgrading Laravel-Mix.
package.json
webpack.mix.js
app.js
For me the information from this answer https://github.com/JeffreyWay/laravel-mix/issues/2747#issuecomment-755483920 fixed my problem
Also the upgrade guide had some useful information - https://github.com/JeffreyWay/laravel-mix/blob/master/UPGRADE.md
Hope this might help :bowtie:
add .vue() on webpack.mix.js file after mix.js()
mix.js(‘resources/js/app.js’, ‘public/js’) .vue() .postCss(‘resources/css/app.css’, ‘public/css’, [ require(‘postcss-import’), require(‘tailwindcss’), ]);
and Then run
npm install vue-resource npm i vue-loader npm install vue-template-compiler npm install vue-router
hope it will work
This works fine
@devhoussam above 2 answers should fix your problem. I think this issue could be closed
I have the same error
Needed
in
webpack.mix.jsin our case running Vue 2.6.14 usingvue.common.jswhich is the full version (compiler and runtime). The CommonJS builds are often used with older bundlers. See Vue Docs Terms .We are using Webpack 5 now, but it seems we need this setup. Also see https://github.com/vuejs-templates/webpack/issues/215 with mention on runtimes