[英]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.