Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Scaffold command fails without @inertiajs/core #242

@dmarcoux

Description

@dmarcoux

Hi,

I've generated a Rails 8 app with the following command:

rails new ./ --name=RssReader --skip --skip-js --skip-asset-pipeline --skip-dev-gems --database=postgresql

In this app, I am setting up Inertia.js by running bin/rails g inertia:install with the following options:

  • Install Vite Ruby: Yes
  • Use TypeScript: Yes
  • What framework to use: React
  • Install Tailwind CSS: Yes
  • Overwrite bin/dev: Yes

So far so good, until I try to scaffold some code with:

bin/rails g scaffold feed title:text description:text link:text last_build_date:datetime managing_editor:text --primary-key-type=uuid

It fails with the following stacktrace:

Stacktrace

❯ bin/rails g inertia:scaffold feed title:text description:text link:text last_build_date:datetime managing_editor:text --primary-key-type=uuid 
      invoke  active_record
      create    db/migrate/20250713201649_create_feeds.rb
      create    app/models/feed.rb
      invoke    rspec
      create      spec/models/feed_spec.rb
      invoke      factory_bot
      create        spec/factories/feeds.rb
      invoke  resource_route
       route    resources :feeds
      invoke  scaffold_controller
      create    app/controllers/feeds_controller.rb
      invoke    inertia_tw_templates
      create      app/frontend/pages/Feed
      create      app/frontend/pages/Feed/Index.tsx
      create      app/frontend/pages/Feed/Edit.tsx
      create      app/frontend/pages/Feed/Show.tsx
      create      app/frontend/pages/Feed/New.tsx
/home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/inertia_rails-3.9.0/lib/inertia_rails/generators/helper.rb:94:in 'block in InertiaRails::Generators::Helper#inertia_js_version': undefined method 'values' for nil (NoMethodError)

            json['dependencies'].values.first['version']
                                ^^^^^^^
	from <internal:kernel>:126:in 'Kernel#then'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/inertia_rails-3.9.0/lib/inertia_rails/generators/helper.rb:93:in 'InertiaRails::Generators::Helper#inertia_js_version'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/inertia_rails-3.9.0/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.tsx.tt:1:in 'Thor::Actions#template'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/erb-5.0.1/lib/erb.rb:427:in 'Kernel#eval'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/erb-5.0.1/lib/erb.rb:427:in 'ERB#result'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/file_manipulation.rb:128:in 'block in Thor::Actions#template'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb:54:in 'Thor::Actions::CreateFile#render'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb:64:in 'block (2 levels) in Thor::Actions::CreateFile#invoke!'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb:64:in 'IO.open'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb:64:in 'block in Thor::Actions::CreateFile#invoke!'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/empty_directory.rb:117:in 'Thor::Actions::EmptyDirectory#invoke_with_conflict_check'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb:61:in 'Thor::Actions::CreateFile#invoke!'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions.rb:93:in 'Thor::Actions#action'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb:25:in 'Thor::Actions#create_file'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/actions/file_manipulation.rb:124:in 'Thor::Actions#template'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/generators/named_base.rb:25:in 'block in Rails::Generators::NamedBase#template'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/generators/named_base.rb:45:in 'Rails::Generators::NamedBase#inside_template'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/generators/named_base.rb:24:in 'Rails::Generators::NamedBase#template'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/inertia_rails-3.9.0/lib/inertia_rails/generators/scaffold_template_base.rb:17:in 'block in InertiaRails::Generators::ScaffoldTemplateBase#copy_view_files'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/inertia_rails-3.9.0/lib/inertia_rails/generators/scaffold_template_base.rb:16:in 'Array#each'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/inertia_rails-3.9.0/lib/inertia_rails/generators/scaffold_template_base.rb:16:in 'InertiaRails::Generators::ScaffoldTemplateBase#copy_view_files'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'block in Thor::Invocation#invoke_all'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Hash#each'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Enumerable#map'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Thor::Invocation#invoke_all'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:243:in 'Thor::Group.dispatch'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:116:in 'Thor::Invocation#invoke'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:288:in 'block in Thor::Group#_invoke_for_class_method'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/shell.rb:68:in 'Thor::Shell#with_padding'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:277:in 'Thor::Group#_invoke_for_class_method'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:134:in 'Inertia::Generators::ScaffoldControllerGenerator#_invoke_from_option_inertia_templates'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'block in Thor::Invocation#invoke_all'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Hash#each'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Enumerable#map'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Thor::Invocation#invoke_all'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:243:in 'Thor::Group.dispatch'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:116:in 'Thor::Invocation#invoke'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:288:in 'block in Thor::Group#_invoke_for_class_method'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/shell.rb:68:in 'Thor::Shell#with_padding'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:277:in 'Thor::Group#_invoke_for_class_method'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:134:in 'Inertia::Generators::ScaffoldGenerator#_invoke_from_option_scaffold_controller'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'block in Thor::Invocation#invoke_all'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Hash#each'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Enumerable#map'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:134:in 'Thor::Invocation#invoke_all'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/group.rb:243:in 'Thor::Group.dispatch'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/base.rb:584:in 'Thor::Base::ClassMethods#start'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/generators.rb:265:in 'Rails::Generators.invoke'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/commands/generate/generate_command.rb:26:in 'Rails::Command::GenerateCommand#perform'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/command/base.rb:178:in 'Rails::Command::Base#invoke_command'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor.rb:538:in 'Thor.dispatch'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/command/base.rb:73:in 'Rails::Command::Base.perform'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/command.rb:65:in 'block in Rails::Command.invoke'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/command.rb:143:in 'Rails::Command.with_argv'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/command.rb:63:in 'Rails::Command.invoke'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/railties-8.0.2/lib/rails/commands.rb:18:in '<main>'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
	from /home/dany/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bootsnap-1.18.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in 'Kernel#require'
	from bin/rails:4:in '<main>'

So by looking at the source code of inertia-rails, this is where it fails:

      def inertia_js_version
        @inertia_js_version ||= Gem::Version.new(
          JSON.parse(`npm ls @inertiajs/core --json`).then do |json|
            json['dependencies'].values.first['version']
          end
        )
      end

I don't know if it's expected, but @inertiajs/core isn't a dependency in package.json, so I installed it manually with npm i @inertiajs/core and running the same scaffold command again succeeded. Now I wonder, should this dependency be added as part of the bin/rails g inertia:install command? It seems, at least according to the docs in the repo, that this dependency is a requirement for some features like server-side rendering.

Let me know if you need some more details.

Thank you for your work on 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