workbox: Precache manifest missing entries when recompiled via webpack --watch
Library Affected: workbox-webpack-plugin
Browser & Platform: Webpack 2.3.3, workbox-webpack-plugin 3.6.3
Issue Description:
In the webpack --watch
mode, precache-manifest.hash.js
file at first generates a perfect list of files, but on subsequent updates it misses some files.
For example, files generated with CopyWebpackPlugin
are missing (but including copyUnmodified: true
in options helps).
Another kind of files that are missing, is fontawesome-webfont.eot?hash
files (importes via this process https://medium.com/@chanonroy/webpack-2-and-font-awesome-icon-importing-59df3364f35c), this I don’t yet know how to fix.
Here is a similar issue for another manifest plugin: https://github.com/danethurber/webpack-manifest-plugin/issues/144.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 19 (6 by maintainers)
Links to this issue
Commits related to this issue
- fix(config): [next] GenerateSW has been called multiple times, perhaps due to running webpack in --watch mode. The precache manifest generated after the first call may be inaccurate! Please see http... — committed to OnrampLab/next-starter by koshuang 4 years ago
- followed https://github.com/GoogleChrome/workbox/issues/1790 to fix weird server/caching issue that prevent accurate hot reload on code changes — committed to alphabetsoop/pwa-react by deleted user 3 years ago
- disabled service worked in dev environment due to https://github.com/GoogleChrome/workbox/issues/1790 — committed to runcitadel/ui by WilliamConnatser 3 years ago
- Migrated to Next.JS, initial project setup continued, more work on the colors and theme, and initial app header design idea (#8) * merge squashed feat/Next.js branch * disabled service worked in d... — committed to runcitadel/ui by WilliamConnatser 3 years ago
- Workbox will now only be loaded in production mode because it's garbage. (https://github.com/GoogleChrome/workbox/issues/1790) — committed to luizzeroxis/webgm by luizzeroxis 2 years ago
- chore: don't register SW in development builds See https://github.com/GoogleChrome/workbox/issues/1790#issuecomment-544982014 — committed to birchill/hikibiki-app by birtles 2 years ago
- Disable PWA while in development. Prevents GenerateSW from being called multiple times in dev. Ref: https://github.com/GoogleChrome/workbox/issues/1790 — committed to wingmatt/habitrack by wingmatt 2 years ago
A similar approach as per @devarthurribeiro, but through the disable option:
My temporary solution. So I can make development lighter:
I don’t know if it’s just because our case is unusual, but this would be very painful for my team. We recently added a Workbox service worker to a legacy application, and getting it right was largely a process of trial and error. Our non-live-reload Webpack build times take minutes to complete, whereas live-reload lets us fail fast and move on.
Basically, sometimes what you’re developing is the service worker itself, or requires the service worker to be present to function (e.g. Notifications on Android Chrome).
We also value having the service worker in live-reload situations because of the concept of dev/prod parity. If developers are always working without the service worker running, they will probably miss issues that can and do arise once a service worker is in play.
FWIW, we went with option 3 above, but it doesn’t save us from getting spammed with redundant warning messages over and over:
P.S. I have some experience writing Webpack plugins, so I do sympathise with how challenging it could be to find a “real” fix for this. I just wanted to plead my case 🙏
As specified in https://www.npmjs.com/package/next-pwa?activeTab=readme#configuration
You can also do:
There aren’t any new solutions at this time. The warning message that gets logged in v5 will hopefully let folks know about the issue while doing local development.
My team has a case where we want to generate and register the service worker in development. This is because we have caching set up in our service-worker for some very large assets that are not a part of our webpack build, and we also want to be able to test and receive push notifications in local development.
If that’s also your case, I figured out this hacky workaround:
You may also need to set
self.__WB_DISABLE_DEV_LOGS = true
in the service-worker source to suppress extraneous warnings in the browser console.There are a few approaches:
service-worker.js
file from your development web server.navigator.serviceWorker.register()
behind aprocess.env.NODE_ENV
check.manifestTransform
in v5. I could imagine persisting theoriginalManifest
parameter outside of the lifetime of a given compilation, and then re-adding any missing manifest entries each time a re-compilation occurs. You’d risk re-adding manifest entries for assets that have been deleted, though, but I guess it’s a development environment and you could deal with some inaccuracy.I’d personally go with one of the first two options, as I think testing your service worker is best done via a “staging” rather than live-reload “development” build.
Is there a recommendation how to use this in dev mode (with watch or dev server)? Turning off the plugin then, obviously results in errors since the service worker is not available. Leaving it on emits a lot of warnings - and the feeling that something might not work as expected.
I don’t get it… Is there a solution that doesn’t require using next.js? Or does next-pwa not require using next.js?
@ezzatron that should be doable.
I don’t think there’s anything more we can do here, other than log the warning on recompilation that we’ve implemented.
based on this workaround, i just added this to my webpack config file, and the warning gone ❤️
So what I’d like to do for the v5 timeframe is add in the
webpack
compilation warning when we detect that re-compilation has occurred, letting folks know that the contents of the precache manifest might be inconsistent.I’m going to explore a bit more to see if there’s anything in the
webpack
internals that could give us the info we need about the complete set of assets, raise issues with thewebpack
maintainers if not, and in all likelihood switch things over to the cumulative asset manifest for the time being.I don’t want to block the v5 release on that work, as it’s likely going to take some time. I feel like adding in the warning about inconsistently gives us some leeway to make this sort of change post-v5, since developers will have a heads-up about not relying on
--watch
for anything production-ready.