Skip to content

Error on fresh install with scaffolded inertia resource #160

@jbwl

Description

@jbwl

Edit: I overlooked the fact that the scaffold generator created .jsx files, which are not picked up by the resolve() method when inertia-rails is configured to use Typescript. The actual issue is that the scaffold generator should create .tsx files, with Typescript inside if possible.

Previous issue text:

I have created a new Rails 8.0 app, and installed inertia-rails following the instructions at https://inertia-rails.dev/guide/server-side-setup#rails-generator.

I can run the app, navigate to /inertia-example, and it works without any errors in the console (great!).

But, then I created an inertia-rails scaffold with

bundle exec bin/rails generate inertia:scaffold Article sku:string title:string

and I can see all the files being created in the right place, and a the resources :articles added to routes.rb
I can confirm I can load Articles from the resource on the console with Article.limit(10) for example.

But when I try to access /articles in the browser, instead of the expected React component showing the list of articles, I get a blank page with an error in the console:

Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'y.default') in createInertiaApp.ts:85

This is the code at createInertiaApp.ts, line 85:

const reactApp = await resolveComponent(initialPage.component).then((initialComponent) => {
    return setup({
      // @ts-expect-error
      el,
      App,
      props: {
        initialPage,
        initialComponent,
        resolveComponent,
        titleCallback: title,
        onHeadUpdate: isServer ? (elements) => (head = elements) : null,
      },
    })
  })

I have not changed or added any files myself, I am using a fresh Rails install, a fresh inertia-rails install, and an unchanged scaffold from inertia-rails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions