workbox: [v5.0.0-beta.1] Can't find self.__WB_MANIFEST in your SW source
Library Affected: workbox-webpack-plugin
Browser & Platform: all browsers
Issue or Feature Request Description: The issue has been introduced in v5.0.0-beta.1
During compilation:
ERROR in Can't find self.__WB_MANIFEST in your SW source.
if I set the injectionPoint
explicitly with the default value (injectionPoint: '__WB_MANIFEST'
), the error is different
ERROR in Can't find data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9ub2RlX21vZHVsZXMvY29yZS1qcy9pbnRlcm5hbHMvYS1mdW5jdGlvbi5qcy5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8uL25vZGVfbW9kdWxlcy9jb3JlLWpzL2ludGVybmFscy9hLWZ1bmN0aW9uLmpzPzFjMGIiXSwic291cmNlc0NvbnRlbnQiOlsibW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiAoaXQpIHtcbiAgaWYgKHR5cGVvZiBpdCAhPSAnZnVuY3Rpb24nKSB7XG4gICAgdGhyb3cgVHlwZUVycm9yKFN0cmluZyhpdCkgKyAnIGlzIG5vdCBhIGZ1bmN0aW9uJyk7XG4gIH0gcmV0dXJuIGl0O1xufTtcbiJdLCJtYXBwaW5ncyI6IkFBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQURBO0FBQ0EiLCJzb3VyY2VSb290IjoiIn0=/n/# in assets.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 17 (7 by maintainers)
Your
swSrc
shows:By default, you need to use
self.__WB_MANIFEST
:(Unless you set
injectionPoint: '__WB_MANIFEST'
, like you said.)Apologies if this specific requirement caught you out while testing the beta releases, especially since we don’t have the documentation in place yet. That’s the default
injectionPoint
that we’re going with in v5 across all the build tools.And again, the second error you encountered, once you got the
injectionPoint
configuration resolved, should be addressed by https://github.com/GoogleChrome/workbox/pull/2251.I have encountered the same error whilst using webpack-workbox-plugin with the
InjectManifest
function. Adding literally justself.__WB_MANIFEST
to the bottom of my Service Worker file seems to have fixed it. I guess the plugin code expects to find this variable in the file and doesn’t like it when it isn’t there. It seems odd that I need to add this (seemingly useless, since I’m not interested in precaching) piece of boilerplate code into my service worker. Is the plugin really not able to do this? It also isn’t in the documentation anywhere that I’d expect it to be. e.g. https://developers.google.com/web/tools/workbox/guides/precache-files/webpackworkbox-webpack-plugin
includesworkbox-build
as a dependency, andworkbox-build
includes all those otherworkbox-*
libraries:https://github.com/GoogleChrome/workbox/blob/dd408f0c17a50fb68cac485133123775c3d4dfc2/packages/workbox-build/package.json#L45-L58
Technically, that should be sufficient, but some package managers (e.g.
yarn
) are not happy if you rely on transitive dependencies, so explicitly listing theworkbox-*
libraries that you use as your own dependencies is probably the best bet. They shouldn’t be installed twice intonode_modules
, as modern package managers know how to deduplicate that as long as the semver ranges match.Hi @jeffposnick
I’m a bit confused. So when using
InjectManifest
ofworkbox-webpack-plugin
we will need to npm install workbox libraries (workbox-core
,workbox-precaching
,workbox-routing
…etc)??Does that mean those will be installed twice (with webpack plugin & separately)?
Is there a way to let
workbox-webpack-plugin
expose them? Or do I have to install them if I want, for example, to callskipWaiting
andclientsClaim()
?Thanks for the answer. I understand the change. Anyway, I still think, by default, the choice to use the global context should be left to the user as it’s the native javascript behavior
It’s just a part of the service worker
While adapting code developed originally for a CRA setup, I had commented out a whole lot of stuff, including the
precacheAndRoute(self.__WB_MANIFEST)
line. What is disconcerting is that this doesn’t seem to be causing an error in--mode development
, only--mode production
, hence me originally thinking it wasn’t required (in spite of the comment in the CRA-generated code).