‘laravel8 + vue3 Cannot read properties of undefined (reading ‘component’)’

‘laravel8 + vue3
error Uncaught TypeError: Cannot read properties of undefined (reading 'component')

how can this error be avoided ?

app.js

window.Vue = require('vue').default;
Vue.component('hello', require('./hello.vue').default);
const app = new Vue({
    el: '#app'
});

welcome.blade.php
<body class="antialiased">
    <div class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center py-4 sm:pt-0">
        <div id="app">
            <hello></hello>
        </div>
    </div>
    <script src="{{mix('js/app.js')}}"></script>
</body>

hello.vue
<template>
    <div>
        Hello World!
    </div>
</template>

package.json
"devDependencies": {
    "@vue/compiler-sfc": "^3.2.11",
    "axios": "^0.21",
    "laravel-mix": "^6.0.6",
    "lodash": "^4.17.19",
    "postcss": "^8.1.14",
    "vue": "^3.2.11",
    "vue-loader": "^16.5.0"
}

this error appears in vue3

tell me how to avoid it

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

in Vue3 Your app.js should be like that:

require('./bootstrap');

import { createApp } from 'vue';
import hello from './components/hello.vue';

let app=createApp({})
app.component('hello' , hello);

app.mount("#app")

Method 2

You are using Vue2 setup. Change it to vue3 as above mentioned.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x