Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
React / TypeScript serviceWorker Update function warning how to resolve

When I try to npm run build I get this error:

Failed to compile.

src/serviceWorker.js
  Line 38:36:  Array.prototype.map() expects a value to be returned at the end of arrow function  array-callback-return


// Update a service worker
/* eslint-disable-next-line no-restricted-globals */
self.addEventListener('activate', (event) => {
  let cacheWhitelist = ['biordle']
  event.waitUntil(
    caches.keys().then((cacheNames) => {
      return Promise.all(
        cacheNames.map((cacheName) => {
          if (cacheWhitelist.indexOf(cacheName) === -1) {
            return caches.delete(cacheName)
          }
        })
      )
    })
  )
})

Here is the error-resulting code:

Failed to compile.

src/serviceWorker.js
  Line 38:36:  Array.prototype.map() expects a value to be returned at the end of arrow function  array-callback-return

A more complete version of the code can be found at this Github Repo: https://github.com/Brayman30/biordle

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It complains because you are returning only in the if statement:

cacheNames.map((cacheName) => {
          if (cacheWhitelist.indexOf(cacheName) === -1) {
            return caches.delete(cacheName)
          }
        })

You should use filter before of map if you want to execute the promise only if cacheWhitelist.indexOf(cacheName) === -1 :

cacheNames.filter((cacheName) => cacheWhitelist.indexOf(cacheName) === -1) ).map((cacheName) => caches.delete(cacheName)
       
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda