Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!