Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!