Library Affected:
"workbox-webpack-plugin": "^5.1.2"
Browser & Platform:
yarn v1.22.4, Webpack Encore 0.28.3
Issue or Feature Request Description:
I just started to use Workbox. I've succesfully created a service worker file and got in working in my web application. The next step is to use InjectManifest, but I am too stupid/the documention is not clear/there is a bug*
I've added this to my webpack config:
.addPlugin(new WorkboxPlugin.InjectManifest({
swSrc: './assets/js/service-worker.js'
}))
But that gives this error:
Can't find self.__WB_MANIFEST in your SW source.
I have no idea what to do. How should the service-worker.js file look like? I can't find any example that works.
_* please strike out whichever is not applicable_
Sorry that you're running into issues.
If you'd like to precache your webpack assets, you'd normally do something like
import {precacheAndRoute} from 'workbox-precaching';
// Your other import statements go here.
precacheAndRoute(self.__WB_MANIFEST);
// Your other SW code goes here.
The InjectManifest plugin will take care of replacing self.__WB_MANIFEST in your swSrc file with an array of assets that will end up precached by your web app, and that final, ready-to-use service worker file will be written out to disk as part of your webpack build process.
I hope that helps. We can revisit this issue if you're still having problems.
I'm using exactly that code, but I'm still getting the error message.
Can you attach the entire contents of your assets/js/service-worker.js file into this issue?
Just this:
import {precacheAndRoute} from 'workbox-precaching';
// Your other import statements go here.
precacheAndRoute(self.__WB_MANIFEST);
// Your other SW code goes here.
Thanks for your quick reply. I tried to create a small project, but that one worked. I'm looking into other webpack settings that may cause this issue. I'll keep you posted.
Edit: I'm sorry, I can't reproduce my problem anymore. Removed all generated files, restarted my project and now everything works.
Most helpful comment
Just this:
Thanks for your quick reply. I tried to create a small project, but that one worked. I'm looking into other webpack settings that may cause this issue. I'll keep you posted.
Edit: I'm sorry, I can't reproduce my problem anymore. Removed all generated files, restarted my project and now everything works.