简体   繁体   English

注册 ServiceWorker 失败:脚本具有不受支持的 MIME 类型 ('text/html')

[英]Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html')

The script has an unsupported MIME type ('text/html').该脚本具有不受支持的 MIME 类型 ('text/html')。 Failed to load resource: net::ERR_INSECURE_RESPONSE (index):1 Uncaught (in promise) DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').无法加载资源:net::ERR_INSECURE_RESPONSE (index):1 Uncaught (in promise) DOMException: Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html')。

Code for template.js root file template.js 根文件的代码

export default ({ markup, css }) => {
  return `<!doctype html>
      <html lang="en">
        <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>MERN Marketplace</title>
          <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400">
          <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
          <style>
              a{
                text-decoration: none
              }
          </style>
          <link rel="manifest" href="./manifest.json">
        </head>
        <body style="margin:0">
            <div id="root">${markup}</div>
          <style id="jss-server-side">${css}</style>

          <script id="stripe-js" src="https://js.stripe.com/v3/" async></script>
          <script type="text/javascript" src="/dist/bundle.js"></script>
          <script>
          if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('/sw.js').then(function() { 
              console.log("Service Worker Registered"); 
            });
          }
          </script>
        </body>
      </html>`;
};

根据我的个人经验,我只是确保sw.js文件与index.html位于同一文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注册时的 ServiceWorker MIME 类型错误 (&#39;text/html&#39;) (React) - ServiceWorker MIME Type Error ('text/html') on register (React) 模拟服务器错误 - 脚本具有不受支持的 MIME 类型 ('text/html') - Mock server error - The script has an unsupported MIME type ('text/html') 不支持MIME类型(&#39;text / html&#39;) - MIME type ('text/html') is not a supported NodeJS,MIME 类型 (&#39;text/html&#39;) 不是受支持的样式表 MIME 类型 - NodeJS, MIME type ('text/html') is not a supported stylesheet MIME type 无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404) - Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script 我收到错误消息:无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404) - I got the error : Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script 类型错误:无法注册 ServiceWorker:获取脚本时收到错误的 HTTP 响应代码 (404) - TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script Webpack / Babel转换的.js文件的MIME类型错误(“ text / html”不是“ text / javascript”) - Webpack/Babel-transformed .js file has wrong MIME type ('text/html' not 'text/javascript') MIME 类型 (&#39;text/html&#39;) 不是受支持的样式表 - MIME type ('text/html') is not a supported stylesheet Express MIME 类型 ('text/html') 上的 Webpack 不可执行 - Webpack on Express MIME type ('text/html') is not executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM