question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Service worker has an unsupported MIME type ('text/html')

See original GitHub issue

Describe the bug

Using the create-react-app-typescript-pwa template to generate a progressive web app returns the following error when `serviceWorker.register() is called:

index.js:1 Error during service worker registration: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/serviceWorker.js'): The script has an unsupported MIME type ('text/html').
  • I’m only able to see the error message after I remove the following condition in the checkValidServiceWorker() function in ./src/serviceWorkerRegistration.ts:
if (
        response.status === 404 ||
        (contentType != null && contentType.indexOf('javascript') === -1)
      ) {

Did you try recovering your dependencies?

Yes

Please paste the output of npm --version and/or yarn --version to confirm. –>

7.6.1

Which terms did you search for in User Guide?

PWA, TypeScript, Workbox, Service worker

Environment

current version of create-react-app: 4.0.3 System: OS: Windows 10 10.0.17763

Steps to reproduce

  • Run npx create-react-app my-app --template cra-template-pwa-typescript
  • modify serviceWorker.unregister() to serviceWorker.register()

Expected behavior

  • Service worker should be registered

Actual behavior

Service worker not registered

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:17
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
psiservices-justin-sullardcommented, Dec 6, 2021

Given this issue was encountered on Windows and seems to match the symptoms we experienced on Windows I’m wondering if this PR would be relevant: https://github.com/facebook/create-react-app/pull/11640

0reactions
eliranmalcommented, Oct 18, 2021

my setup is an unejected create-react-app application, built using the vanilla javascript variant of the pwa package.

i’m not sure anymore that the problem can be resolved by manually copying the file. i believe that’s the job of the workbox plugin (that eventually receives this file’s path), but for some reason it’s blocked in development (i presume due known issues with the devserver).

can’t help much more 🤷

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service Worker registration error: Unsupported MIME type ...
Error during service worker registration: DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html ...
Read more >
The script has an unsupported MIME type ('text/html')
I get following error: The script has an unsupported MIME type ('text/html'). service worker error DOMException: Failed to register a ...
Read more >
ServiceWorker MIME Type Error ('text/html') on register (React)
The current behavior: Service worker does not register due to the below error ... The script has an unsupported MIME type ('text/html'). console....
Read more >
Unsupported MIME type ('text/html')-Reactjs - appsloveworld
Coding example for the question Service Worker registration error: Unsupported MIME type ('text/html')-Reactjs.
Read more >
The script has an unsupported MIME type ('text/js')
[This thread is closed.] I am getting error in the browser console The script has an unsupported MIME type ('text/js') and also getting…...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found