WorkboxError non-precached-url index.html error in Quasar PWA

78 Views Asked by At

I have a problem in my pwa related to the title error, this is my custom-service-worker.js

console error

/* eslint-env serviceworker */

/*
 * This file (which will be your service worker)
 * is picked up by the build system ONLY if
 * quasar.config.js > pwa > workboxMode is set to "injectManifest"
 */

import { clientsClaim } from "workbox-core";
import {
  precacheAndRoute,
  cleanupOutdatedCaches,
  createHandlerBoundToURL,
} from "workbox-precaching";
import { registerRoute, NavigationRoute } from "workbox-routing";

skipWaiting();
clientsClaim();

// Receive push notifications
self.addEventListener("push", function (e) {
  if (!(self.Notification && self.Notification.permission === "granted")) {
    return;
  }
  if (e.data) {
    const message = e.data.json();
    console.log(message);
    e.waitUntil(
      self.registration
        .showNotification(message.title, {
          body: message.body,
          icon: message.icon,
          actions: message.actions,
        })
  
    );
  }
});

self.addEventListener(
  "notificationclick",
  (event) => {
    event.notification.close();
    console.log(event);
    if (event.action) {
      clients.openWindow(event.action);
    }
  },
  false
);

// Use with precache injection
precacheAndRoute(self.__WB_MANIFEST);

cleanupOutdatedCaches();

// Non-SSR fallback to index.html
// Production SSR fallback to offline.html (except for dev)
if (process.env.MODE !== "ssr" || process.env.PROD) {
  registerRoute(
    new NavigationRoute(
      createHandlerBoundToURL(process.env.PWA_FALLBACK_HTML),
      { denylist: [/sw\.js$/, /workbox-(.)*\.js$/] }
    )
  );
}

The only thing I added are the push events, the rest is as it comes by default in Quasar.

and the problem comes in this block:

if (process.env.MODE !== "ssr" || process.env.PROD) {
  registerRoute(
    new NavigationRoute(
      createHandlerBoundToURL(process.env.PWA_FALLBACK_HTML),
      { denylist: [/sw\.js$/, /workbox-(.)*\.js$/] }
    )
  );
}

If I leave it I get that error, but that's how it comes by default and I don't think I should remove it, so I don't know if I'm missing something.

This is my pwa configuration in quasar.config

   pwa: {
      workboxMode: "injectManifest", // or 'injectManifest'
      injectPwaMetaTags: true,
      swFilename: "sw.js",
      manifestFilename: "manifest.json",
      useCredentialsForManifestTag: false,
      // useFilenameHashes: true,
      // extendGenerateSWOptions (cfg) {}
      // extendInjectManifestOptions (cfg) {},
      // extendManifestJson (json) {}
      // extendPWACustomSWConf (esbuildConf) {}
    },

as a side note, i use quasar with vite.

I'm trying to run it in dev mode and I hope it compiles well without error.

0

There are 0 best solutions below