简体   繁体   English

CRA - 无法注册 ServiceWorker,不支持的 MIME 类型 ('text/html')

[英]CRA - Failed to register a ServiceWorker, unsupported MIME type ('text/html')

I am getting the following error when publishing my create react app but the error doesn't appear locally.发布我的 create react 应用程序时出现以下错误,但该错误未在本地出现。 I recently updated my React version and a load of packages too.我最近更新了我的 React 版本和一些包。 I'm guessing it's possibly something to do with that as I've never had this issue before?我猜这可能与此有关,因为我以前从未遇到过这个问题?

Error during service worker registration: DOMException: Failed to register a ServiceWorker for scope ('https://**subdomain**.azurewebsites.net/') with script ('https://**subdomain**.azurewebsites.net/service-worker.js'): The script has an unsupported MIME type ('text/html').

Any input on this will be greatly appreciated.对此的任何意见将不胜感激。 The error doesn't appear to be breaking anything from what I can see but I'd rather not push this to production with any kind of errors该错误似乎没有破坏我所看到的任何内容,但我宁愿不要将其推向生产并出现任何类型的错误

So turns out the issue was because I updated the react version.原来问题是因为我更新了反应版本。 CRA doesn't have service workers out of the box anymore. CRA 不再有开箱即用的服务人员。 The project was returning 'unsupported MIME type ('text/html')' because it was hitting 404 looking for a file that doesn't exist.该项目正在返回“不支持的 MIME 类型 ('text/html')”,因为它在查找不存在的文件时遇到 404。 The fix was relativly simple.修复相对简单。 I replaced the registerServiceWorker() in my index.js file with reportWebVitals() .我将index.js文件中的registerServiceWorker()替换为reportWebVitals() I then added reportWebVitals.js to my src folder.然后我将reportWebVitals.js添加到我的 src 文件夹中。 (I just created a temp react project and pulled the file from that). (我刚刚创建了一个临时反应项目并从中提取文件)。 After I did that it started to work for me.在我这样做之后,它开始为我工作。 I think I also had to npm install web-vitals.我想我还必须 npm 安装 web-vitals。

暂无
暂无

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

相关问题 注册 ServiceWorker 失败:脚本具有不受支持的 MIME 类型 ('text/html') - Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html') MSW:无法使用脚本为范围注册 ServiceWorker 该脚本具有不受支持的 MIME 类型('text/html') - MSW: Failed to register a ServiceWorker for scope with script The script has an unsupported MIME type ('text/html') 无法为 scope 注册 ServiceWorker - 脚本具有不受支持的 MIME 类型 ('text/html') - Failed to register a ServiceWorker for scope - The script has an unsupported MIME type ('text/html') 注册 ServiceWorker 失败:脚本的 MIME 类型不受支持 - reactjs - Failed to register a ServiceWorker: The script has an unsupported MIME type - reactjs 注册时的 ServiceWorker MIME 类型错误 ('text/html') (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') Service Worker 注册错误:不支持的 MIME 类型('text/html') - Service Worker registration error: Unsupported MIME type ('text/html') Firebase TypeScript 上的 FCM:“脚本具有不受支持的 MIME 类型('text/html') - Firebase FCM on TypeScript: "The script has an unsupported MIME type ('text/html') firebaseerror:无法注册ServiceWorker - firebaseerror: Failed to register a ServiceWorker 正在获取 脚本具有不受支持的 MIME 类型('text/html')。 从 React JS 前端获取 FCM 令牌时 - Getting The script has an unsupported MIME type ('text/html'). while getting FCM token from react js frontend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM