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

hjortur17's avatar

Laravel and Vue error

Hi, I was starting a new product and trying to use VueJS but it gives me the error

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

I'm trying to echo out message from app.js

    
/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.component('example-component', require('./components/ExampleComponent.vue'));

const app = new Vue({
    el: '#app'
    data: {
        message: 'Hello World'
    }
});

And this is my master.blade.php file

    <div id="app">
        @include ('partials.navbar')

        @yield ('header')

        @yield ('content1')
    
        @yield ('content2')

        @include ('partials.contact')

        @include ('partials.footer')

        {{ message }}
    </div>
0 likes
21 replies
ejdelmonico's avatar

So, I am supposed to guess what resource is not loading as the error message indicates? Come on now.

Vuejs is not the cause of your server error.

hjortur17's avatar

So I'm using this extension on Chrome but it says that Vue is not detected.

I'm trying to bug fix Vue JS be simple to print out and Hello World message and I have my script tag in the bottom of my master.blade.php layout file and then a div#app over that

ejdelmonico's avatar

Sometimes you have to close chrome dev tools and then open it again for chrome to detect the plugin.

Comment out your partials and includes because your vue code is fine.

Oh, you must compile your JS too.

hjortur17's avatar

And the error message is:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)          portfolio.test/
ejdelmonico's avatar

Is that file the one you are trying to echo out message in? If not, then get rid of that file...move it temporarily and run again.

hjortur17's avatar

Now I get

Use of undefined constant message - assumed 'message' (this will throw an Error in a future version of PHP) (View: /Users//websites/portfolio/resources/views/layouts/master.blade.php) (View: /Users//websites/portfolio/resources/views/layouts/master.blade.php)

ejdelmonico's avatar

Ok, it seems that Vue is maybe not compiled. Have you run npm install and then npm run dev?

ejdelmonico's avatar

Hmm, what are you using to run the site? Valet? Homestead?

Also, make sure you are linking to the app.js file in your layout.

hjortur17's avatar

I have another product and using VUE there and it's no problem

ejdelmonico's avatar

Show your layout so we can make sure you are showing you JS and CSS files from mix output. If not using versioning, then use:

// in head
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

// end of body
<script src="{{ asset('js/app.js') }}"></script>

Seems like Vue is not available to me.

hjortur17's avatar
<title>Hjörtur Freyr - Web Developer</title>

{{-- STYLESHEET --}}
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script defer src="https://pro.fontawesome.com/releases/v5.0.13/js/all.js" integrity="sha384-d84LGg2pm9KhR4mCAs3N29GQ4OYNy+K+FBHX8WhimHpPm86c839++MDABegrZ3gn" crossorigin="anonymous"></script>

{{-- @include ('partials.navbar')
    @yield ('header')

    @yield ('content1')

    @yield ('content2')

    @include ('partials.contact')

    @include ('partials.footer') --}}

    {{ message }}
</div>

<script src="{{ asset('js/app.js') }}"></script>

Just added these lines but nothing changed

hjortur17's avatar
hjortur17
OP
Best Answer
Level 14

I got it to work! I had to add @ in front of {{message}}

Linugux's avatar

:) Excelente ... thanks .... @{{ message }}

Please or to participate in this conversation.