Mind Dump, Tech And Life Blog
written by Ivan Alenko
published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
posted at 24. Aug '21

Webpacker In Rails Engine Doesn’t Work

Webpacker in Rails 6.0.3 engines is not integrated very well. I mean, spend two weeks configuring webpack and it might work. And will be coupled. I tried to follow three guides, but two of them had serious limitations and one didn’t work.

Failures:

  1) welcome page shows articles
     Failure/Error: <%= stylesheet_pack_tag 'application', media: 'all' %>

     ActionView::Template::Error:
       undefined method `stylesheet_pack_tag' for #<#<Class:0x00007f9678134ca8>:0x00007f967813f3b0>
       Did you mean?  stylesheet_path
                      stylesheet_link_tag
     # ./spec/dummy/app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb__3341715273681785289_70142118227440'
     # ./spec/requests/welcome_spec.rb:6:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `stylesheet_pack_tag' for #<#<Class:0x00007f9678134ca8>:0x00007f967813f3b0>
     #   Did you mean?  stylesheet_path
     #                  stylesheet_link_tag
     #   ./spec/dummy/app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb__3341715273681785289_70142118227440'

Finished in 0.50944 seconds (files took 3.19 seconds to load)
10 examples, 1 failure

It is possible to get it to work, but then JS in engine won’t be separated and package.json of an engine needs to be included in host app including same versions.

Add Comment