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,
})
]
})
)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With