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

undefined method `asset_pack_path' when referring to Webpacker entry packs #89

Open
feliperaul opened this issue Oct 27, 2020 · 1 comment

Comments

@feliperaul
Copy link

I'm trying to refer to my Webpacker entry packs (JS and CSS) in my serviceworker.js.erb file, however it's throwing the following JS exception:

Uncaught Error: NoMethodError: undefined method `asset_pack_path' for #<#<Class:0x00007fa5b7856448>:0x00007fa5b89255d0>
Did you mean?  asset_path

Here's my serviceworker.js.erb file:

<% helpers = ActionController::Base.helpers %>

var CACHE_NAME = 'v1-cached-assets';

function onInstall(event) {
  event.waitUntil(
    caches.open(CACHE_NAME).then(function prefill(cache) {
      return cache.addAll([
        '<%= asset_path "application.js" %>', // This works
        '<%= asset_path "application.css" %>', // This works
        '<%= asset_pack_path 'some_entry_pack.js' %>', // This explodes
      ]);
    })
  );
}
@MikeRogers0
Copy link

MikeRogers0 commented Jan 25, 2021

I ran into this problem also. I did try to use Webpacker.instance.manifest.lookup, but I think because the Webpacker assets are compiled after this is compiled it'll always return nil :/

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