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

363
Vistas
When I try to register a service worker file in react app it will give me a reference error: navigator is not defined
export default function swDev() {
    let swUrl = `${process.env.PUBLIC_URL}/sw.js`
    if('serviceWorker' in navigator) {
        navigator.serviceWorker.register(swUrl).then((res) => {
            console.warn("response", res)
        }).catch((err) => {
            console.warn("error is: ", err)
        })
    } else {
        console.log("service worker is not supported")
    } 
}

this is the following code I have also called this function in index.js file in my react app. Also created a simple sw.js file with a message that file is attached.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should as well check if window is defined. The service worker should only be initialized client side

(typeof window != 'undefined' && window.document);
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