andywer / threads.js

🧵 Make web workers & worker threads as simple as a function call.
https://threads.js.org/
MIT License
3.04k stars 161 forks source link

Worker Path Module not found #463

Open anwarjaved opened 1 year ago

anwarjaved commented 1 year ago

I am trying to load Worker from same directory in nodejs typescript it always throws Error: Cannot find module I tried to load using relative path and also by absolute path but it always failed

appocalypseltd commented 1 year ago

Was literally about to post the same message...I have this:

import { Pool, spawn, Worker } from 'threads';
import * as w from './Worker';

export class EngineLearn {
  trainModels = async () => {
    const pool = Pool(() => spawn(new Worker('./Worker')));
    // ...do stuff with pool
  };
}

Error: Cannot find module 'engine-learn/Worker`

I am using @nrwl/esbuild:esbuild with Nx.