Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workbox 5 syntax error - Uncaught TypeError: workbox.expiration.CacheableResponsePlugin is not a constructor

Tags:

workbox

I'm trying to set up a simple Service Worker for a small static site, but I get a service worker console error:

sw.js:59 Uncaught TypeError: workbox.expiration.CacheableResponsePlugin is not a constructor

This is at the line new workbox.expiration.CacheableResponsePlugin

Any suggestions on how to fix this would be appreciated.

  workbox.routing.registerRoute(
    /\.(?:html)$/,
    new workbox.strategies.NetworkFirst({
      cacheName: 'html-cache',
      plugins: [
        new workbox.expiration.CacheableResponsePlugin({
          statuses: [0, 200],
        }),

        new workbox.expiration.ExpirationPlugin({
          maxEntries: 50,
          maxAgeSeconds: 5 * 60,
        })
      ]
    })
  )
like image 479
JohnC Avatar asked Feb 19 '20 22:02

JohnC


1 Answers

I was migrating from workbox v4 to v5 and having the same problem.

In your code,

new workbox.expiration.CacheableResponsePlugin

should be

new workbox.cacheableResponse.CacheableResponsePlugin
like image 150
bob Avatar answered Oct 11 '22 15:10

bob