简体   繁体   English

尝试删除 Service Worker 时如何修复 ESLint 错误

[英]How to fix ESLint Error when trying to remove service worker

Based on this answer How do I uninstall a Service Worker?基于此答案如何卸载 Service Worker? Removing service worker can be done with the bellow code:删除 service worker 可以使用以下代码完成:

navigator.serviceWorker.getRegistrations().then(function(registrations) {
 for(let registration of registrations) {
  registration.unregister()
} })

When I add it.当我添加它时。 ESLint has the following error: ESLint 有以下错误:

error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them.错误迭代器/生成器需要 regenerator-runtime,这对于本指南来说太重了,不允许它们。 Separately, loops should be avoided in favor of array iterations no-restricted-syntax另外,应避免循环以支持数组迭代无限制语法

Any idea how to rewrite this code to make ESLint not complain?知道如何重写此代码以使 ESLint 不抱怨吗?

Modify the code like this, and use Object.entries/Object.keys/Object.values depending on use-case with forEach :像这样修改代码,并根据用例使用Object.entries/Object.keys/Object.valuesforEach

navigator.serviceWorker.getRegistrations().then(function(registrations) {
 Object.entries(registrations).forEach(registration =>{
  registration.unregister()
}) })

From the GitHub Issue for the error you mentioned.来自您提到的错误的GitHub 问题

You could use any of the array iterators mentioned in the link.您可以使用链接中提到的任何数组迭代器。

registrations.forEach(function (registration) {
  registration.unregister();
});

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

相关问题 如何修复ESLint错误使用数组解构 - How to fix ESLint error Use array destructuring 如何修复 Eslint 错误“prefer-destructuring”? - How to fix Eslint error “prefer-destructuring”? 如何解决“无参数重新分配”的错误? - How to fix “no-param-reassign” eslint error? 如何修复此ESLint / JSDoc语法错误? - How to fix this ESLint/JSDoc syntax error? 使用节点时如何修复 eslint 错误:导入 Node.js 内置模块时的协议 - How to fix eslint error when using the node: protocol when importing Node.js builtin modules 在代码中包含@popperjs/core 和 eslint 时如何修复意外的 Webpack 错误 - How to fix unexpected Webpack error when including @popperjs/core and eslint in code 如何手动强制删除旧的服务人员 - How to manually force remove a old service worker React typescript eslint 错误解析错误:意外的令牌? 如何解决这个问题? - React typescript eslint error Parsing error: Unexpected token ! How to fix this? 安装Service Worker时出现DOMExecption错误 - DOMExecption error when installing service worker 如何解决服务人员导航“此服务人员不是客户端的活动服务人员”错误? - How to solve service worker navigate "This service worker is not the client's active service worker" error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM