Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on fresh install with scaffolded inertia resource #160

Closed
jbwl opened this issue Nov 12, 2024 · 1 comment
Closed

Error on fresh install with scaffolded inertia resource #160

jbwl opened this issue Nov 12, 2024 · 1 comment

Comments

@jbwl
Copy link

jbwl commented Nov 12, 2024

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.

@skryukov
Copy link
Contributor

Hey, @jbwl, thanks for the issue!

Yes, the documentation includes a note about that:

The inertia_rails-contrib gem doesn't include Rails scaffold generators for TypeScript yet.

I'm working on that issue in this PR: #158

@jbwl jbwl closed this as completed Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants