vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite
https://vite-pwa-org.netlify.app/
MIT License
2.9k stars 197 forks source link

Service Worker "import" error when sourcemapping #641

Open ArnauKokoro opened 5 months ago

ArnauKokoro commented 5 months ago

Hi,

I'm addressing this issue to you.

https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/460

Thanks!

userquin commented 5 months ago

can you add type: 'module' in PWA devOptions entry? Since sentry is adding an import to the sw in dev mode, this plugin doesn't include anything in the sw (it is build by workbox-build module):

;import "/@id/__x00__sentry-release-injection-file";
ArnauKokoro commented 5 months ago

Adding type: 'module' on VitePWA devOptions I'm having same error on dev mode.

Thanks!

userquin commented 5 months ago

can you provide a minimal repro?

ArnauKokoro commented 5 months ago

Just running yarn dev

This is what chrome console says: Uncaught SyntaxError: Cannot use import statement outside a module (at dev-sw.js?dev-sw:96:2)

And these are the lines of dev-sw.js:

define(['./workbox-9637eeee'], (function(workbox) {
    'use strict';

    self.addEventListener('message', event=>{
        if (event.data && event.data.type === 'SKIP_WAITING') {
            self.skipWaiting();
        }
    }
    );

    /**
   * The precacheAndRoute() method efficiently caches and responds to
   * requests for URLs in the manifest.
   * See https://goo.gl/S9QRab
   */
    workbox.precacheAndRoute([{
        "url": "index.html",
        "revision": "0.fp20qtanrkg"
    }], {});
    workbox.cleanupOutdatedCaches();
    workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"),{
        allowlist: [/^\/$/]
    }));

}
));
//# sourceMappingURL=sw.js.map

;import "/@id/__x00__sentry-release-injection-file";
//# sourceMappingURL=data:application/json;base64;xxx
yuri-ellfort commented 3 months ago

Any updates here? @ArnauKokoro have you found a solution?

ArnauKokoro commented 3 months ago

Hi @yuri-ellfort,

When is development mode i'm setting globPatterns to [].

userquin commented 2 months ago

sentry an pwa plugin or pwa plugin integrations cannot be used with generateSW strategy, check: https://github.com/vite-pwa/nuxt/issues/132