1

Error Throwing in the console Log The script has an unsupported MIME type ('text/html').

Service worker registration failed with: DOMException: Failed to register a ServiceWorker for scope ('https://localhost:4000/') with script ('https://localhost:4000/ngsw-worker.js'): The script has an unsupported MIME type ('text/html').
Techie Sakthi
  • 73
  • 1
  • 8

2 Answers2

2

Try

ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production, scope: './', registrationStrategy: 'registerImmediately' })

inside app.module.ts

canbax
  • 3,432
  • 1
  • 27
  • 44
0

In my case service worker was twice registered.

Once from index.html

  <script type="text/javascript">

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/serviceworker').then(function (registration) {
    console.log('ServiceWorker registration successful with scope: ', registration.scope);
  }, function (err) {
    console.log('ServiceWorker registration failed: ', err);
  });
}

Second time by

ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })

inside app.module.ts

//ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })

Solved my problem.

Carl S.
  • 69
  • 1
  • 1
  • 8