简体   繁体   中英

Service worker registration failed -- PWA Not working after Universal Prerendering implementation in Angular 9

控制台日志中抛出错误脚本具有不受支持的 MIME 类型 ('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').

Try

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

inside app.module.ts

In my case service worker was twice registered.

  <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);
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM