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

Ifrit's avatar
Level 2

Getting Inertia to work

I installed laravel and I'm trying to use inertia with it, but when after installing it and almost getting it to work, I'm now getting this error in my console

[Vue warn]: Error in render: "SyntaxError: Unexpected token u in JSON at position 0"

This is my app.js file

require('./bootstrap');

require('moment');

import Vue from 'vue';

import { InertiaApp } from '@inertiajs/inertia-vue';

Vue.use(InertiaApp);

const app = document.getElementById('app');

new Vue({
    render: (h) =>
        h(InertiaApp, {
            props: {
                initialPage: JSON.parse(app.dataset.page),
                resolveComponent: (name) => require(`./Pages/${name}`).default,
            },
        }),
}).$mount(app);
0 likes
7 replies
sr57's avatar

@ifrit

Which version of Laravel?

How do you install Laravel & Inertia?

chrispage1's avatar

Hi,

For anyone else looking for the solution. This happens because you haven't run the @inertia directive within your template file. Note: you cannot run this directive within a layout file, it has to be within the main template that Inertia is using.

This template file is defined within the App\Http\Middleware\HandleInertiaRequests middleware as a protected variable called $rootView.

1 like
baumgars's avatar

The app.js file posted here does not compile here with npm run watch following only the official guide. And i do have @inertia placed in my app.blade.php but still the same error.

slavatar's avatar

For anyone who still might Google this: I had a slightly different issue that was causing the error. My main template file app.blade.php had a <body id="app">.

The @inertia tag also renders a <div id="app>", with a whole bunch of data in the data-page attribute. This resulted in a page with a double #app element which obviously broke everything, so removing the id from the body tag fixed the issue.

Please or to participate in this conversation.