2

I followed the server-side and client-side instructions on the InertiaJS website for setting it up in an existing Laravel project.

This is my app.jsx file:

import { createInertiaApp } from '@inertiajs/react'
import { createRoot } from 'react-dom/client'

createInertiaApp({
  resolve: name => {
    const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true })
    return pages[`./Pages/${name}.jsx`]
  },
  setup({ el, App, props }) {
    createRoot(el).render(<App {...props} />)
  },
})

I have the following in resources/js/Pages/HelloWorld.jsx:

import React from 'react'
import { Head } from '@inertiajs/react'

export default function HelloWorld () {
  return (
    <div>
      <Head title="Hello World" />
      <h1>Hello World</h1>
    </div>
  )
}

And the following in routes/web.php:

Route::get('/hello', function () {
    return \Inertia\Inertia::render('HelloWorld');
});

When I run the server and visit /hello I get a blank page with an error in the console saying React is not defined.

I have tried npm install react and npm install react-dom with no success. I have tried clearing cache, deleting node_modules and running npm install again. It continues to just say that React is not defined.

What could be the issue?

0

1 Answer 1

2

You need to install@vitejs/plugin-react

https://laravel.com/docs/10.x/vite#react

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.