webpacker: Getting undefined method `javascript_pack_tag' for ...

Having Rails 5 application and followed this tutorial https://medium.com/statuscode/introducing-webpacker-7136d66cddfb#.4xpiogt9l how to install and run webpacker.

Having webpacker in Gemfile

gem 'webpacker', github: 'rails/webpacker'

And used installation commands

rails webpacker:install
rails webpacker:install:react

And when open page with <%= javascript_pack_tag 'app' %> I am getting undefined method 'javascript_pack_tag' for #<#<Class:0x007f8d5a158378>:0x007f8d5a0015b0>

./bin/webpack-dev-server runs fine (but having some babel errors, but I guess that can’t have impact on previous error).

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 12
  • Comments: 33 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Don’t forget to restart your server :trollface:

Please could you all try latest master - bundle update webpacker. This issue is now fixed 🎉 🍰

I had to stop the server, then run bin/spring stop then rails s Then, the javascript_pack_tag worked. (Restarting the server wasn’t sufficient.)

But what has me curious is that I didn’t need to start bin/webpack-dev-server (I thought that was my problem originally) I am curious when, and where, that is needed.

I ran into a similar issue when adding webpacker erb support.

For me (and hopefully anyone reading this), the issue was caused by the js-style comment (as suggested earlier by another comment):

// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb

The solution is to make sure there is no <% ... tags anywhere in the code, including JS comments.

I’ve also run into this issue on rails 5.1.0.rc2 the project is using active admin but it doesn’t use any before_action configuration. I’ve not had a change to look into what is causing this as yet and the work around fixes the issue for now. If I get a chance to look into this more deeply I’ll report back here.

@schovi Could you please add require 'webpacker/railtie' in the list and then retry running without including helper in the controller? The one I have got require 'rails/all', which means it adds everything.

If yes to above, do you got javascript comments in that file? Please remove that since it’s erb. I have made a demo for you here - https://tranquil-inlet-61365.herokuapp.com/ and code is here - https://github.com/gauravtiwari/webpacker-demo-app