roxiness/routify-starter

Uncomment service worker in main.js leads to error (2.x)

chbert opened this issue · 4 comments

Mac OS X 10.15.7
Node 14.8.0

How to reproduce:

  1. npx @sveltech/routify init --branch 2.x
  2. open main.js > uncomment line 11-18
  3. npm install
  4. npm run dev
  5. open localhost:5000
  6. console error:
PrecacheController.js:55 Uncaught TypeError: entries is not iterable
    at PrecacheController.addToCacheList (PrecacheController.js:55)
    at precache (precache.js:50)
    at precacheAndRoute (precacheAndRoute.js:26)
    at sw.js:43
    at sw.js:98
addToCacheList @ PrecacheController.js:55
precache @ precache.js:50
precacheAndRoute @ precacheAndRoute.js:26
(anonymous) @ sw.js:43
(anonymous) @ sw.js:98
localhost/:1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('http://localhost:5000/') with script ('http://localhost:5000/sw.js'): ServiceWorker script evaluation failed

Was this only an issue with npm run dev and not npm run build && npm run serve?

I can comfirm it works with npm run build && npm run serve but with npm run dev (or dev-dynamic) it gives the error.

afbeelding(firefox)

It's because self.__WB_MANIFEST doesn't get injected in 2.x, use 2.x-simplified instead or setup rollup-plugin-workbox like it is in the 2.x-simplified branch.
But 2.x-simplified currently has another issue with service workers as the file doesn't get copied into the correct folder; you can manually fix this tho by moving the built serviceworker.js file into /assets/ or /dist/ (where e.g. robots.txt is at too).

I've updated 2x-simplified. The service worker should work now.