shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.71k stars 312 forks source link

The script has an unsupported MIME type ('text/html'). #483

Open AllanOliveiraM opened 12 months ago

AllanOliveiraM commented 12 months ago

Summary

I caught this error on Sentry:

SecurityError: Failed to register a ServiceWorker for scope ('my_domain.../') with script ('my_domain.../sw.js'): The script has an unsupported MIME type ('text/html').

I have done extensive research and found that other people have encountered the same issue with CRA, but I'm having trouble understanding what to do with Next. I have several clients who are unable to install the PWA due to this error, mostly on mobile devices. What's interesting is that some of them are up to date and should support PWAs.

Versions

How To Reproduce

I couldn't reproduce it in a controlled environment. It's happening on multiple people's devices. I'm able to capture the exceptions with Sentry, and when I analyze what people are seeing on Hotjar, they're indeed unable to install the app.

Steps to reproduce the behavior:

Apparently, customers access the website, and during the script loading, the browser already raises this exception.

Expected Behaviors

It should be possible to register the service worker.

Screenshots

image

😢

Any ideas on where should I start to solve this?

AllanOliveiraM commented 12 months ago

I found this issue https://github.com/shadowwalker/next-pwa/issues/479 Maybe? I'm not sure if it's the same case, but there's a good chance it is. I tried accessing the /sw.js file to see if it was there, and yes, it was. Everything works fine on the computer.