rails/importmap-rails

Class `Importmap` undefined (constant uninitiated) after gem installed and bundled

nimmolo opened this issue · 1 comments

Rails
6.1 or 7.0, same behavior.

Ruby
3.1.2

The gem importmap-rails bundles, but the class does not load. Do i need to require it?

Adding require "importmap/engine" to config/application.rb gets NameError: uninitialized constant Importmap

Without a require...

  • in Rails console, the whole class instantiated by the gem, Importmap, is an uninitialized constant.
  • the install task, rails importmap:install, is “not found”
  • a view helper, <%= javascript_import_tags %>, is “not defined”

Maybe related to #196

I can't really tell anything from this error message:

rails aborted!
Don't know how to build task 'importmap:install' (See the list of available tasks with `rails --tasks`)
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:159:in `invoke_task'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.7.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.7.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.7.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.7.2/lib/rails/command.rb:51:in `invoke'
/home/vagrant/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.7.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:6:in `require'
bin/rails:6:in `<main>'

VM
Vagrant running ubuntu/jammy64

Agh. It was because the gem was in a group, in the Gemfile, so the class didn't get required.