question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vendor.[revision].js not pushed in self.__SW_MANIFEST

See original GitHub issue

In a vue2 app using @vue/composition-api and vite, the vendor.[revision].js is not present in the self.__WB_MANIFEST variable in service worker.

Here is how the plugin is configured un my vite.config.ts:

    VitePWA({
      mode: 'development',
      srcDir: 'src',
      filename: 'sw.ts',
      base: '/',
      strategies: 'injectManifest',
      registerType: 'autoUpdate',
      includeAssets: ['/favicon.svg'], // <== don't remove slash, for testing purposes
      manifest: {
        name: 'myApp',
        short_name: 'myApp',
        theme_color: '#0070B2',
        icons: [
          {
            src: '/pwa-192x192.png', // <== don't remove slash, for testing purposes
            sizes: '192x192',
            type: 'image/png',
          },
          {
            src: '/pwa-512x512.png', // <== don't remove slash, for testing purposes
            sizes: '512x512',
            type: 'image/png',
          }
        ],
      }
    })

registerSW.ts that is imported in main.ts (because virtual:pwa-register/vue can’t be used with vue 2):

import { registerSW } from 'virtual:pwa-register'

function handleSWManualUpdates(swRegistration: ServiceWorkerRegistration | undefined) {
  // noop
}

function handleSWRegisterError(error: any) {
  // noop
}

try {
  const updateSW = registerSW({
    immediate: true,
    onOfflineReady() {
      console.log("onOfflineReady")
    },
    onNeedRefresh() {
      console.log("onNeedRefresh")
    },
    onRegistered(swRegistration) {
      swRegistration && handleSWManualUpdates(swRegistration)
    },
    onRegisterError(e) {
      handleSWRegisterError(e)
    }
  })
} catch {
  console.log("PWA disabled.")
}

the service worker himself:

import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching'
import { clientsClaim } from 'workbox-core'
declare let self: ServiceWorkerGlobalScope

precacheAndRoute(self.__WB_MANIFEST)

self.skipWaiting()
clientsClaim()

cleanupOutdatedCaches()

self.addEventListener('message', (event) => {
  if (event.data && event.data.type === 'SKIP_WAITING')
    self.skipWaiting()
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
vcastro45commented, Oct 1, 2021

@userquin looks good to me Thanks for your prompt response and fix

1reaction
vcastro45commented, Sep 30, 2021

@userquin After some more investigations, I resolved the problem. I had to increase the value of the maximumFileSizeToCacheInBytes variable in config (that is a part of the workbox config editable through the VitePWA config). The default value is 3000000 bytes and I needed more.

I don’t know if it is an issue for Workbox or vite-plugin-pwa but in my opinion it must show an error in the console, but it still silent.

Here is the config to add:

injectManifest: {
  maximumFileSizeToCacheInBytes: 3000000 // Change this value to your needs
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Viewing online file analysis results for 'WebPage.pdf'
This report is generated from a file or URL submitted to this webservice on ... Not all malicious and suspicious indicators are displayed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found