Uncomment service worker in main.js leads to error (2.x)
chbert opened this issue · 4 comments
chbert commented
Mac OS X 10.15.7
Node 14.8.0
How to reproduce:
- npx @sveltech/routify init --branch 2.x
- open main.js > uncomment line 11-18
- npm install
- npm run dev
- open localhost:5000
- 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
jakobrosenberg commented
Was this only an issue with npm run dev
and not npm run build && npm run serve
?
lalilaloe commented
Kneemund commented
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).
jakobrosenberg commented
I've updated 2x-simplified. The service worker should work now.