I'm attempting to utilize vue.js's capabilities for progressive web apps by creating a customized service worker using workbox. However, every time I try to build the app, I encounter the following error:
AssertionError [ERR_ASSERTION]: swSrc must be set to the path to an existing service worker file.
In my project/vue.config.js file:
module.exports = {
runtimeCompiler: true,
pwa: {
workboxPluginMode: "InjectManifest",
plugins: [
new InjectManifest({
swSrc: "src/service-worker.js"
})
]
}
};
And in my project/src/service-worker.js file:
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
//Web Push Notifications//
let click_open_url;
self.addEventListener("push", function(event) {
let push_message = event.data.json();
// push notification can send event.data.json() as well
click_open_url = push_message.notification.data.url;
const options = {
body: push_message.notification.body,
icon: push_message.notification.icon,
image: push_message.notification.image,
tag: "alert"
};
event.waitUntil(
self.registration.showNotification(push_message.notification.title, options)
);
});
self.addEventListener("notificationclick", function(event) {
const clickedNotification = event.notification;
clickedNotification.close();
if (click_open_url) {
const promiseChain = clients.openWindow(click_open_url);
event.waitUntil(promiseChain);
}
});
I've experimented with altering the formatting of swSrc, such as adding ./
or just /
, and even removing src/
, but none of these changes have resolved the issue. I've also tried copying code generated by workbox and pasting it into service-worker.js, but it still doesn't recognize it. How can I make InjectManifest acknowledge my service worker file?