service-workerworkboxquasar

Multiple instances of self.__WB_MANIFEST


(Related to this question)

I am using quasar v2.0.0-beta.5 and "workbox-webpack-plugin": "^5.1.4", following a pwa tutorial. I am now working on the service workers part using workboxPluginMode: 'InjectManifest' in quasar.conf.js. My custom-service-worker.js is just:

import { precacheAndRoute } from 'workbox-precaching'
precacheAndRoute(self.__WB_MANIFEST)

I get the following error when loading the pwa

Uncaught not-an-array: The parameter 'entries' passed into 'workbox-precaching.PrecacheController.addToCacheList()' must be an array

I have updated to lastest version of Workbox: npm install --save-dev workbox-webpack-plugin@^6.1.0 to see if it makes a difference and now I get the following error during the quasar dev -m pwa

Multiple instances of self.__WB_MANIFEST were found in your SW source. Include it only once. For more info, see GoogleChrome/workbox#2681

The problem is that without fixing this problem, I am not able to debug the different cache strategies.

Platform (please complete the following information): Quasar Version: v2.0.0-beta.5 @quasar/app Version: v3.0.0-beta.7 Quasar mode: [ ] SPA [ ] SSR [x ] PWA [ ] Electron [ ] Cordova [ ] Capacitor [ ] BEX Tested on: [ ] SPA [ ] SSR [x ] PWA [ ] Electron [ ] Cordova [ ] Capacitor [ ] BEX OS: windows 10 Node: v14.15.1 NPM: 6.14.8 Yarn: 1.22.10 Browsers: chrome (latest) iOS: Android: Electron:


Solution

  • Do this in your service worker file.

    if (process.env.NODE_ENV === 'production') {
      precacheAndRoute(self.__WB_MANIFEST);
    }