0

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

2 回答 2

2

尝试

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

里面app.module.ts

于 2020-03-13T12:03:11.013 回答
0

在我的情况下,服务人员注册了两次。

一次来自 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);
  });
}

第二次由

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

在 app.module.ts 里面

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

解决了我的问题。

于 2022-02-03T15:36:38.920 回答