Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda