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

simcha's avatar

vite - inertia - react

I followed this guide: https://dev.to/kodeas/using-vite-with-inertia-laravel-vue-tailwind-2h5k

The difference: I need to react

Everything seems fine except for this section:

import { InertiaProgress } from '@inertiajs/progress'
...

InertiaProgress.init()
createInertiaApp({
    resolve: name => {
        const page = require(`./Pages/${name}`).default

        if(page.layout === undefined && name.startsWith('SuperAdmin/Company/')){
            page.layout = page => (<AdminLayout>
                <LayoutCompany>{page}</LayoutCompany>
            </AdminLayout>)
        }
		...
        return page;
    },
    setup({ el, App, props }) {
        render(<App {...props} />, el)
    },
})

I get the following error

 > resources/js/app.js:15:35: error: Unexpected "<"      
    15 │             page.layout = page => (<AdminLayout>
       ╵  

What can help?

0 likes
10 replies
Sinnbeck's avatar

Did you forget to import react?

import React from 'react'
simcha's avatar

@Sinnbeck Of course I brought that too

I have reduced the code I copied here to a minimum

Sinnbeck's avatar

According to the docs it just takes the import of the layout

page.layout = page => AdminLayout

In the AdminLayout component you can do the nesting

simcha's avatar

@Sinnbeck Until I changed to vite everything worked fine, I do not think that is the problem

Sinnbeck's avatar

Well I am using react with vite myself and its working fine. I am using an older version of inertia though. This is how my resolveComponent looks. This might be needed for the rest to work :)

resolveComponent={async (name) => {
                const pages = import.meta.glob('./Pages/**/*.jsx');

                return (await pages[`./Pages/${name}.jsx`]()).default;
            }}
Sinnbeck's avatar

Here is my best guess as to how yours should look

resolve: name => {
        const pages = import.meta.glob('./Pages/**/*.jsx');

        const page = (await pages[`./Pages/${name}.jsx`]()).default;

        if(page.layout === undefined && name.startsWith('SuperAdmin/Company/')){
            page.layout = page => (<AdminLayout>
                <LayoutCompany>{page}</LayoutCompany>
            </AdminLayout>)
        }
		...
        return page;
    },
simcha's avatar
simcha
OP
Best Answer
Level 7

I found the right answer

I have worked so far with mix

And the file extensions are js

vite requires jsx extensions

Sinnbeck's avatar

@simcha Oh sorry my examples didn't help then. At least post the full working example and set that as best answer.

Sinnbeck's avatar

@simcha Remember to test with both vite and vite prod.. They are not the same (prod is compiling with rollup)

1 like

Please or to participate in this conversation.