kevinmarrec / nuxt-pwa-module

⚠️ DEPRECATED ⚠️ Zero config PWA solution for Nuxt 3
MIT License
338 stars 32 forks source link

Error when trying to update the ServiceWorker #34

Closed re2005 closed 1 year ago

re2005 commented 1 year ago

I'm using this plugin and it does works nicely.

But my Sentry report is getting spammed with a lot of errors that comes as Unhandled

Failed to update a ServiceWorker for scope ('https://app....') with script ('https://app.../sw.js'): An unknown error occurred when fetching the script.

I can't manage to find the root cause. I've already set the base, scope urls but still the same.

export const pwaConfig: Partial<VitePWAOptions> = {
    registerType: 'prompt',
    minify: true,
    scope: '/',
    base: '/',
    manifest: {
        scope: '/',

One thing I noticed is that if you are deploying your application and your UI request the sw.js file it will failed also with unhandled so maybe this is something that can be managed differently.

This is my configuration:

<script lang="ts" setup>
    import { useRegisterSW } from 'virtual:pwa-register/vue';
    import { ref } from 'vue';

    const isLoading = ref(false);
    const intervalMS = 45 * 1000;
    const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW({
        onRegistered(r) {
            r &&
                setInterval(() => {
                    r.update();
                }, intervalMS);
        },
    });

    const handleUpdate = () => {
        isLoading.value = true;
        updateServiceWorker();
    };

    const close = async () => {
        offlineReady.value = false;
        needRefresh.value = false;
    };
</script>

Any help is more than welcome since the amount of errors is pilling up and I may have to consider stop using the plugin or look into another solution.

Thanks!

kevinmarrec commented 1 year ago

@re2005 I'm not sure why you're talking about Vite PWA Options, as this module does not use it ?

As well as your configuration using useRegisterSW, which is not a part of this module. Maybe were you trying to find help on https://github.com/antfu/vite-plugin-pwa instead ?

re2005 commented 1 year ago

@kevinmarrec you are 100% right, I'm sorry about the confusion.

Do you think this module will work on Vite 2 or 3 ? I'll give it a try.

Cheers.

kevinmarrec commented 1 year ago

If you're not using Nuxt : Use Vite PWA plugin. If you're using Nuxt : Use this module.

:)