Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda