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

173
Views
Local tensorflow.js won't work as a module in webworker

I'm using a local copy of tensorflow.js tfjs.js in an experimental setup. All is browser side, no node.js.

I want to move the tensorflow functionality to it's own thread in a webworker since it's heavy on the browser. However the way I got the tensorflow module to work in a worker does not make sense:

This was the initial idea:

//main.js
let predictor = new Worker ('prediction_ww.js', {type: 'module'})

//prediction_ww.js
import * as tf from "tfjs.js" 

But this produces the following error when I start execution (note: 'loadGraphModel' is a method in tensorflow.js):

prediction_ww.js:44 Uncaught (in promise) TypeError: tf.loadGraphModel is not a function...
etc...

After testing without a real idea of what I'm doing I get this code, without the type: 'module' to work:

//main.js
let predictor = new Worker ('prediction_ww.js')

//prediction_ww.js
var tf = import ("./tfjs.js")

I would like to understand why this works but not the case using module which my reading suggests should be the correct way of using an external module in a webworker on the browserside.

Also I noticed it only works using the ./ before the filename which I also don't understand why.

I use Chrome 96 on macOS 10.14.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, tfjs works just fine in a web worker unless you try to use specific functions that rely on DOM (e.g. can't use tf.browser.* methods) - and that's not the case here.

When you say local tfjs.js - which variation of tfjs is that? it ships as many variations and only ESM modules can be loaded using {type: "module"}

Default tf.js is NOT ESM, but tf.es2017.js is

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