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

171
Vistas
Cannot use import statement outside a module when importing modules in a web worker

I'm trying to import a module in a web worker that imports another module and getting the following error Uncaught SyntaxError: Cannot use import statement outside a module. My web worker is importing scripts like this:

importScripts(
  './utils.js',
  './nn.js'
);

The error points to the second line with './utils.js', but its actual origin is the first line of utils.js which is the following:

import * as DG from 'datagrok-api/dg';

I tried setting "type": "module" in package.json, but it results in me being unable to compile my project with Webpack and produces other errors.

I also tried to create a worker with new Worker('my.worker.js', {type: "module"}) so I can use import statements in it, but in this case I'm unable to post a message to the worker and not even getting any error. Also module workers are not supported anywhere except for Chrome.

I tried to manage web workers with workerize-loader, but it doesn't work with Webpack 5 which I'm using.

So my question is: how can I import a module in a web worker that contains module imports?

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