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
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)