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

207
Vistas
How to import functions to web worker?

I need to use two modules, originally in Typescript, inside my Javascript web worker. Webpack seems to be taking care about the compatibility problem. Now, to use the modules, I've tried using both require and import.

require gives me Uncaught ReferenceError: require is not defined, which, according to what I found, is because you can't use it on the browser, therefore import is the viable option. import, however, gives me Uncaught SyntaxError: Cannot use import statement outside a module, to which I found a possible solution in here, but while adding { type: "module" } to the constructor does make the error go away, it also makes it so that my worker stops functioning.

In the file that calls worker = new Worker(path, { type: "module" }), I have a worker.postMessage(msg) call. In the worker, there is a

self.addEventListener('message', (e) => {
    doThingsWith(e)
    [...]
    self.postMessage(something)
}

event listener. From the moment I add type: "module", anything inside the event listener does not work.

about 4 years ago · Juan Pablo Isaza
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