vite-plugin-pwa: WorkboxError non-precached-url index.html
Hi, thank you for this plugin.
I’m getting the error below when running the app with vite preview and in production. The app source code is available at https://github.com/jonian/awmonitor and the production link is https://awmonitor.netlify.app.
WorkboxError.js:28 Uncaught (in promise) non-precached-url: non-precached-url :: [{"url":"index.html"}]
at x.createHandlerBoundToURL (http://localhost:5000/workbox-a59a8da5.js:1:12967)
at Object.createHandlerBoundToURL (http://localhost:5000/workbox-a59a8da5.js:1:14597)
at http://localhost:5000/sw.js:1:10085
at http://localhost:5000/sw.js:1:695
s @ WorkboxError.js:28
createHandlerBoundToURL @ PrecacheController.js:276
(anonymous) @ createHandlerBoundToURL.js:29
(anonymous) @ sw.js:486
(anonymous) @ sw.js:1
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 15 (7 by maintainers)
Commits related to this issue
- add workox workaround for icon fonts caching reported in antfu/vite-plugin-pwa#120 — committed to jonian/awmonitor by jonian 3 years ago
I use this config now - not sure if it’s fully correct but seems to be working:
This seems to remove the generated config containing the index.html, which is then just handled by the server.
Thanks. I was having the same issue here, this config. helped out.
Well, the problem is on your
workbox.globPatternsentry: you need to include all, it is exclusive, that is, if you include this entry, you MUST add all your patterns, not only font assets: in your case, you are not including js and css assets andindex.htmlpage.Since you are using
vite, all entries underassetsdirectory will be included, you don’t need to add them again.Just remove the
workboxentry from your configuration:You also need to add all red entries shown bellow to make it work offline, it is working, but some images missing:
I made a quick PR to update the type docs: https://github.com/GoogleChrome/workbox/pull/3106
@userquin I have got a similar problem, how can i exclude the html file.
Sorry to pickup an old thread here, however this is causing some confusion for me.
I’m using Vite to SSR a page, however the
index.htmlfile gets added to the client bundle even though it’s not served by users. My server returns the HTML, however with the index.html file being cached, it’s returning the version of my html which is missing things (e.g. I replace<!-- app-head -->on the server to add metadata). The SW kicks in and serves the cached file instead of the server.If I add the html file to the ignore glob, I get the
non-precached-url: non-precached-urlerror described here.